socialforge/app/models/org_document_comment.rb

21 lines
944 B
Ruby

class OrgDocumentComment < ActiveRecord::Base
attr_accessible :content, :creator_id, :organization_id, :parent_id, :reply_id, :title,:sticky,:locked
include Redmine::SafeAttributes
belongs_to :organization
belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id'
acts_as_tree :order => "#{OrgDocumentComment.table_name}.sticky asc, #{OrgDocumentComment.table_name}.created_at desc"
has_many :org_acts, :class_name => 'OrgActivity',:as =>:org_act ,:dependent => :destroy
after_create :document_save_as_org_activity
def document_save_as_org_activity
if(self.parent().nil?)
self.org_acts << OrgActivity.new(:user_id => User.current.id, :container_id => self.organization.id, :container_type => 'Organization')
else
act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", self.root.id).first
act.update_attributes(:updated_at => self.updated_at)
end
end
end