Hi,
Let's say you have two models which can be associated in different ways:
A User has many conversations they have created. (one to many) A User has many conversations in which they are involved. (many to many)
My first thought was to store the id of the user who created the conversation in the conversations table, and associate users involved in a conversation in a join table.
class User < ActiveRecord::Base
has_many :conversations
has_and_belongs_to_many :conversations
end
class Conversation < ActiveRecord::Base
belongs_to :user
has_and_belongs_to_many :users
end
This seems to be asking for trouble though.
What's the right way to do this? Basically I want to be able to utilise user.conversations for those involved in and user.started_conversations for those started by user.
Thanks.