2015-08-19 17:29:05 +08:00
|
|
|
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
|
2015-08-19 17:29:05 +08:00
|
|
|
|
|
|
|
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
|
2015-08-19 17:29:05 +08:00
|
|
|
end
|