Skip to content

Instantly share code, notes, and snippets.

@djvs
Last active February 7, 2016 07:18
Show Gist options
  • Save djvs/75e1b3ec23b57331c745 to your computer and use it in GitHub Desktop.
Save djvs/75e1b3ec23b57331c745 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
[...]
has_many :msgtos, :class_name => "Message", :foreign_key => :recipient_id #, :inverse_of => :from
has_many :msgfroms, :class_name => "Message",:foreign_key => :sender_id #, :inverse_of => :to
end
class Message < ActiveRecord::Base
belongs_to :to, class_name: "User", :foreign_key => :recipient_id, :inverse_of => :msgfroms
belongs_to :from, class_name: "User", :foreign_key => :sender_id, :inverse_of => :msgtos
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment