Skip to content

Instantly share code, notes, and snippets.

@JFickel
Created September 27, 2012 03:38
Show Gist options
  • Save JFickel/3792036 to your computer and use it in GitHub Desktop.
Save JFickel/3792036 to your computer and use it in GitHub Desktop.
Note Domain Modeling
class Note < ActiveRecord::Base
attr_accessible :description, :sender_id, :user_recipient_id, :team_recipient_id, :tournament_recipient_id
belongs_to :sender, class_name: "User"
belongs_to :user_recipient, class_name: "User"
belongs_to :team_recipient, class_name: "Team"
belongs_to :tournament_recipient, class_name: "Tournament"
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, foreign_key: "user_recipient_id",
class_name: "Note",
dependent: :destroy
has_many :received_notes, through: :incoming_notes, source: :sender
end
class Team < ActiveRecord::Base
has_many :incoming_notes, foreign_key: "team_recipient_id",
class_name: "Note",
dependent: :destroy
has_many :received_notes, through: :incoming_notes, source: :sender
end
class Tournament < ActiveRecord::Base
has_many :incoming_notes, foreign_key: "tournament_recipient_id",
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