I have a user profile model with the following schema:
schema "user_profiles" do
field :birthday, Ecto.Date
field :gender, :string
field :first_name, :string
field :last_name, :string
field :description, :string
field :username, :string
# Associations
belongs_to :user, User
timestamps
end
I also have a location model with the following schema:
schema "locations" do
field :name, :string
field :admin_1, :string
field :admin_2, :string
field :country, :string
field :country_abbreviation, :string
field :code, :string
field :latitude, :decimal
field :longitude, :decimal
timestamps
end
A location is a city like Paris, France. Many user profiles can be associated with the same location. But a location doesn't really need to be aware that user profiles exist.
I want to add a location association to the user profile schema. I do not want to user has_one because the relationship is not one-to-one. I do not want to add any associations on the location schema to user profile, either.
I have looked at the documentation for Ecto and I am at a loss for how to express this association.
I have consulted the following page: https://hexdocs.pm/ecto/Ecto.Schema.html
I am probably missing something basic but I did try more than a few things before asking this question.
location_profiles. Here is a link that goes into more detail: link - Harrison Lucas