One way `has_many` relationships
Are you able to have a has_many relationship where it's just one way? I.e. I have a User resource which can have many List resources but I don't every really care about List resources knowing which users it belongs to
6 Replies
You can do it, but typically you want the foreign key that gets created from having a
belongs_to
relationship back to the other resource
You can define private?
relationships if you want the relationship to be usable internally but not exposed anywhereBut what about if multiple users can own the same list?
oh, then you'd want a
many_to_many
relationship
and then the foreign key lives on the join resourceAhh gotcha. I saw that in the docs but for some reason it's only obvious when you say it lol
So in the future I may want one user who is the "primary" owner of a List and other users who are contributors. Would I model that as a
has_many
/belongs_to
for the List and primary User, and then a many_to_many
/join resource for the contributors?You could do that, but you could also have a join resource that has a
primary?
attribute
We don't have has_one + through
yet but at some point we willOkay cool. Thanks!