Re: Multiple relations between two models

Thorsten L
Thu, 19 Oct 2006 12:10:14 -0000

i think you got something twisted up.
-> in the model, you say, the sender''s foreign key is
"user_id"
-> in the controller, you assign the recipient ( params[:message][:to])
to the column "user_id"

>From what you described i guess you have a foreign_key "sender" in
your
message table that shold hold the ID of the user who sent the message,
and the "user_id" filed should hold the name of the recipient of the
message
Your column naming could be more self-explanatory, e.g. use
"recipient_id" as i suggested in my above post

i think, your :belongs_to sould look like this:

belongs_to :sender, :class_name "User", :foreign_key =>
"sender"
belongs_to :recipient, :class_name "User", :foreign_key =>
"user_id"

but you should give some more info, like your exact table layout etc
...
and what do the parameters hold? i guess params[:message][:to] hold the
recipients name. well you need that user''s id, not his name.

But im just guessing here, not enough insight and info....