Sign In

`belongs_to` likes a singular name

In Ecto, there is a convenient keyword to represent a relationship between schemas. One of the building blocks is "belongs_to." I found that the name of the association should remain in singular form.
I asked why this is the case. It seems that the naming is based on convention, but Ecto actually infers the foreign key name from the association name.

Bad

schema "albums" do
  # field definitions here
  belongs_to :artists, MusicDB.Artist
end  

Good

schema "albums" do
  # field definitions here
  belongs_to :artist, MusicDB.Artist
end