socialforge/app/models/memo_message.rb

18 lines
523 B
Ruby
Raw Normal View History

class MemoMessage < ActiveRecord::Base
attr_accessible :forum_id, :memo_id, :memo_type, :user_id, :viewed
belongs_to :memo
belongs_to :user
2015-08-24 22:47:48 +08:00
has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy
validates :user_id,presence: true
validates :forum_id,presence: true
validates :memo_id,presence: true
validates :memo_type, presence: true
2015-08-24 22:47:48 +08:00
after_create :add_user_message
def add_user_message
self.message_alls << MessageAll.new(:user_id => self.user_id)
end
end