Ecto belongs_to and has_one question

ecto

#1

Hi.
I’m just trying to get my head around belongs_to and has_one. In such a relationship should only one of the tables have a reference to the other table or would I expect to have a reference in each table. For example if I have User and Account and they have a 1 to 1 relationship. Would I expect only one of these tables to reference the other or would user hold an account_id and account hold a user_id?

many thanks

Dave


#2

I believe it works the same as a has_many relationship as far as foreign keys go. Whichever has the belongs_to in its schema would be the one that has the reference id.


#3

Thanks DIW - makes perfect sense. Also the reason why I shouldn’t code with a glass of wine!