Let's say I have a user model and a contacts model (contacts contains
name, phone number, email, etc. of people that the user knows). The
models would be
User:
has_many :contacts
Contact:
belongs_to :user
Now let's say I wanted to introduce groups, where the user could place
certain contacts into groups. Some contacts would be in multiple
groups, others wouldn't be in groups at all. What would be the best
way to model this?
But I'm not sure if this really works. How can I guarantee that a
contact in a group really belongs to the user (maybe I can't through
the model and need to do it in code but that seems so unRails like).
Thanks for the response but actually contacts are not other users - I
should have made that clearer. Rather than it being a social-graph
type application, it's more like contact management, so contacts
belong to the user but are not associated with other users in any way.
If they were, your implementation makes perfect sense, but we're
actually dealing with 3 models here not 2.