@ -3,8 +3,10 @@ class OpenSourceProject < ActiveRecord::Base
include Redmine :: SafeAttributes
has_many :applies , :class_name = > " ApplyProjectMaster " , :as = > :apply , :dependent = > :delete_all
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 , :class_name = > 'RelativeMemo' , :foreign_key = > 'osp_id' , :dependent = > :destroy
has_many :relation_topics , :class_name = > 'RelativeMemoToOpenSourceProject' , :foreign_key = > 'osp_id' , :order = > " #{ RelativeMemo . table_name } .created_at DESC " , :dependent = > :destroy
# 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 :topics , :through = > :relation_topics , :class_name = > 'RelativeMemo'
# has_many :relative_memos, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :dependent => :destroy
has_many :tags , :through = > :project_tags , :class_name = > 'Tag'
has_many :project_tags , :class_name = > 'ProjectTags'
has_many :masters , :class_name = > 'ApplyProjectMaster' , :as = > :apply , :dependent = > :delete_all , :conditions = > " #{ ApplyProjectMaster . table_name } .status = 2 "
@ -126,9 +128,14 @@ class OpenSourceProject < ActiveRecord::Base
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 } ) " ,
# 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])
update_all ( " topic_count = (SELECT COUNT(*) FROM #{ RelativeMemoToOpenSourceProject . table_name } WHERE osp_id= #{ osp_id } ) " ,
# +
# " 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