Programming Phoenix LiveView B7: page 156

Wasn’t sure whether this was an error of omission or just confusion on my part as I’m new to Ecto. It turned out to be the latter. Not sure how to make it more clear though - perhaps I was just a bit too tired when reading this.

The text is:

While we’re here in the Ratings schema, let’s make a few other changes. First, we’ll update the schema to reflect that ratings belong to both users and products. That way, we’ll have access to the existing user_id and product_id fields on our Rating struct. Add a call to the belongs_to macro for both User and Product, like this:

schema "ratings" do
  field :stars, :integer
  belongs_to :user, User
  belongs_to :product, Product

  timestamps()
end
The existing schema was this:
  schema "ratings" do
    field :stars, :integer
    field :user_id, :id
    field :product_id, :id
    timestamps()
  end

It wasn’t clear to me whether the user_id and product_id would be auto generated by the macro. I found the answer here:
https://hexdocs.pm/ecto/Ecto.Schema.html#belongs_to/3