Skip to content

Instantly share code, notes, and snippets.

@JFickel
Created September 27, 2012 04:02
Show Gist options
  • Save JFickel/3792082 to your computer and use it in GitHub Desktop.
Save JFickel/3792082 to your computer and use it in GitHub Desktop.
edit
class Note < ActiveRecord::Base
attr_accessible :description, :sender_id, :receivable_id
belongs_to :sender, class_name: "User"
belongs_to :receivable
end
class User < ActiveRecord::Base
has_many :notes, foreign_key: "sender_id", dependent: :destroy
has_many :outgoing_notes, through: :notes, source: :user_recipient
has_many :incoming_notes, as: :receivable ,
class_name: "Note",
dependent: :destroy
has_many :received_notes, through: :incoming_notes, source: :sender
end
class Team < ActiveRecord::Base
has_many :incoming_notes, as: :receivable,
class_name: "Note",
dependent: :destroy
has_many :received_notes, through: :incoming_notes, source: :sender
end
class Tournament < ActiveRecord::Base
has_many :incoming_notes, as: :receivable,
class_name: "Note",
dependent: :destroy
has_many :received_notes, through: :incoming_notes, source: :sender
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment