2017-04-07 10:16:13 +08:00
class Blog < ActiveRecord :: Base
# attr_accessible :title, :body
include Redmine :: SafeAttributes
belongs_to :user
2017-04-20 17:17:02 +08:00
has_many :articles , :class_name = > 'BlogComment' , :conditions = > " #{ BlogComment . table_name } .parent_id IS NULL " , :order = > " #{ BlogComment . table_name } .created_at DESC "
has_many :blog_comments , :dependent = > :destroy , :order = > " #{ BlogComment . table_name } .created_at DESC "
2017-04-07 10:16:13 +08:00
belongs_to :last_comment , :class_name = > 'BlogComment' , :foreign_key = > :last_comment_id
acts_as_tree :dependent = > :nullify
#acts_as_list :scope => '(user_id = #{user_id} AND parent_id #{user_id ? = "#{parent_id}" : "IS NULL"})'
acts_as_watchable
validates :name , presence : true , length : { maximum : 30 }
validates :description , length : { maximum : 255 }
safe_attributes 'name' , 'description'
end