I am setting up private messaging in my application and was wondering what the best way to do this would be, I have a message model that has 2 columns, a to_id and from_id
I have the association set in the message model like so:
class Message < ActiveRecord::Base
belongs_to :recipient, :class_name => 'User', :foreign_key => "to_id"
belongs_to :sender, :class_name => 'User', :foreign_key => "from_id"
end
How would i set up the relationship in the user model? i want to have a :received messages association and a :sent_messages Association.
Thanks
You can specify the
:foreign_keyon both sides, like this:I know Rails 3 has an
:inverse_ofoption you can pass as well, but I don’t have any experience with that.