Skip to content

Instantly share code, notes, and snippets.

@noahhendrix
Created September 2, 2011 06:50
Show Gist options
  • Save noahhendrix/1188059 to your computer and use it in GitHub Desktop.
Save noahhendrix/1188059 to your computer and use it in GitHub Desktop.
Message Example
class Message < ActiveRecord::Base
belongs_to :recipient, :class => 'User'
belongs_to :sender, :class => 'User'
end
class User < ActiveRecord::Base
has_many :messages, :foreign_key => :recipient_id, :dependent => :destroy
has_many :sent_messages, :foreign_key => :sender_id, :class => 'Message', :dependent => :destroy
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment