Quick question (I think). I have users, and I would like to allow them to send messages to one another. My question is, should I have a user table, a message table, and a users to messages join table, or should I just store to_user_id and from_user_id in the messages table. If the latter, what would the association look like for that? Can you even reference a ‘local’ key for an association?
Share
You can do that with a couple of simple
has_manyassociations. Since it’s self-referential, you’ll need to override some of the Rails magic to make it work.Rails doesn’t have a cleaner way to doing self-referential associations that I know of.