class Blog < ActiveRecord::Base
  # attr_accessible :title, :body
  include Redmine::SafeAttributes
  belongs_to :user
  has_many :articles, :class_name => 'BlogComment', :conditions => "#{BlogComment.table_name}.parent_id IS NULL ", :order => "#{BlogComment.table_name}.created_on DESC"
  has_many :blog_comments, :dependent => :destroy, :order => "#{BlogComment.table_name}.created_on DESC"
  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
