SaThot wrote in post #957715:> I have two models User and Message, every message have one sender and
> many recievers.
First thing to understand is that there is no many-to-many association
here. As you said a Message belongs_to a user and Message has many
recipients, which are Users. So you basically just need to add a foreign
key to User to keep track of the one-to-many relation Message <--->>
User. We just need to do a bit of convention overriding to accomplish
this:
User
has_many :messages
Message
belongs_to :user
has_many :recipients, :class_name => "User", :foreign_key =>
:recipient_message_id
Or if you want to make things more clear you could do:
Message
belongs_to :sender, :class_name => "User", :foreign_key =>
:sender_id
has_many :recipients, :class_name => "User", :foreign_key =>
:recipient_message_id
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.