Skip to content

Instantly share code, notes, and snippets.

@john-bai
Created August 7, 2013 00:05
Show Gist options
  • Select an option

  • Save john-bai/6170086 to your computer and use it in GitHub Desktop.

Select an option

Save john-bai/6170086 to your computer and use it in GitHub Desktop.
class Notification < ActiveRecord::Base
belongs_to :sender, class_name: "User"
belongs_to :receiver, class_name: "User"
validates :sender_id, presence: true
validates :receiver_id, presence: true
attr_accessible :sender_id, :receiver_id
end
class User < ActiveRecord::Base
has_many :notifications, foreign_key: "sender_id", dependent: :destroy
has_many :reverse_notifications, foreign_key: "receiver_id", class_name: "Notification", dependent: :destroy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment