26 lines
1.1 KiB
Ruby
26 lines
1.1 KiB
Ruby
class OpenSourceProject < ActiveRecord::Base
|
|
attr_accessible :String
|
|
|
|
include Redmine::SafeAttributes
|
|
has_many :topics, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :conditions => "#{RelativeMemo.table_name}.parent_id IS NULL", :order => "#{RelativeMemo.table_name}.created_at DESC", :dependent => :destroy
|
|
has_many :relative_memos, :dependent => :destroy
|
|
has_many :tags, :through => :project_tags, :class_name => 'Tag'
|
|
has_many :project_tags, :class_name => 'ProjectTags'
|
|
acts_as_taggable
|
|
def short_description(length = 255)
|
|
description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
|
|
end
|
|
|
|
def reset_counters!
|
|
self.class.reset_counters!(id)
|
|
end
|
|
|
|
def self.reset_counters!(id)
|
|
osp_id = id.to_i
|
|
update_all("topic_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NULL)," +
|
|
" memo_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NOT NULL)," +
|
|
" last_memo_id = (SELECT MAX(id) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id})",
|
|
["id = ?", osp_id])
|
|
end
|
|
end
|