I’m programming a RPG website with Rails 3.1 and I’ve got a User model (fields don’t matter much).
What I need is to be able to marry two users but I don’t know what’s the best way for the associations.
I’ve thought of user1 and user2 as columns but I don’t know how to say that both are the same when associating it to the User model in order to know whether a User is married or not. (that’s to say that a user id can be on one column or the other one…)
Thank you in advance !
If it’s always one to one you could set it up like this:
Which should handle the inverse relationship as well, e.g.
If you need
Marriageas a class, the marriage could just relate to users throughhas_manyand validate that the # of users is 2 (if it’s a traditional marriage). E.g. if you went the STI route: