Ecto for Elixir: Foreign Key
<p>I have a user profile model with the following schema:</p>

<pre><code>  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
</code></pre>

<p>I also have a location model with the following schema:</p>

<pre><code>  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
</code></pre>

<p>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.</p>

<p>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.</p>

<p>I have looked at the documentation for Ecto and I am at a loss for how to express this association.</p>

<p>I have consulted the following page:
<a href="https://hexdocs.pm/ecto/Ecto.Schema.html" rel="nofollow">https://hexdocs.pm/ecto/Ecto.Schema.html</a></p>

<p>I am probably missing something basic but I did try more than a few things before asking this question.</p>