I have a table called ‘users’. I have a second table called ‘comments’.
The comments table is in need of two columns that both reference
different user ids within the ‘users’ table (one column for the user id
that originated the post, another column for the user id for which the
message is intended for.
Obviously I can’t create two columns named ‘user_id’. How do I go about
creating two columns that reference the same foreign column?
I have a table called ‘users’. I have a second table called ‘comments’.
The comments table is in need of two columns that both reference
different user ids within the ‘users’ table (one column for the user id
that originated the post, another column for the user id for which the
message is intended for.
Obviously I can’t create two columns named ‘user_id’. How do I go about
creating two columns that reference the same foreign column?
class User < ActiveRecord::Base
has_many :sent_comments, :class_name => ‘Comment’, :conditions =>
“sender_user_id = #{self.id}”
has_many :received_comments, :class_name => ‘Comment’, :conditions =>
“recipient_user_id = #{self.id}”
end