You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
764 B
21 lines
764 B
class BlogMessage < ActiveRecord::Base
|
|
# attr_accessible :title, :body
|
|
attr_accessible :content, :blog_message_id, :blog_message_type, :viewed, :user_id, :blog_id, :user_operator_id
|
|
|
|
belongs_to :blog_comment ,:polymorphic => true
|
|
belongs_to :user
|
|
has_many :message_alls, :class_name => 'MessageAll', :as => :message, :dependent => :destroy
|
|
|
|
validates :user_id, presence: true
|
|
validates :blog_id, presence: true
|
|
validates :blog_message_id, presence: true
|
|
validates :blog_message_type, presence: true
|
|
after_create :add_user_message
|
|
|
|
def add_user_message
|
|
if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil?
|
|
self.message_alls << MessageAll.new(:user_id => self.user_id)
|
|
end
|
|
end
|
|
end
|