Tuesday, September 25, 2007

Tutorial: Foreign Keys with Different Names

I had to make private messages that had a sender_id and a recipient_id that both referred to the user table. Here's how the model should look:


class PrivateMessage < ActiveRecord::Base
belongs_to :sender, :class_name => "User", :foreign_key => "sender_id"
belongs_to :recipient, :class_name => "User", :foreign_key => "recipient_id"
end

No comments: