diff --git a/app/models/course.rb b/app/models/course.rb index 79b8c068..796ea3c9 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -177,7 +177,7 @@ class Course < ActiveRecord::Base end def member_count - Member.find_by_sql("select count(id) as count from members where course_id=#{self.id}").first.try(:count).to_i + CourseMember.find_by_sql("select count(id) as count from course_members where course_id=#{self.id}").first.try(:count).to_i end def self.search(query) @@ -257,7 +257,7 @@ class Course < ActiveRecord::Base # 选出教师数不为0的答辩组 def course_graduation_group - self.graduation_groups.select{|group| group.members.count > 0} + self.graduation_groups.select{|group| group.course_members.count > 0} end # 课程的短描述信息 @@ -420,11 +420,12 @@ class Course < ActiveRecord::Base # 删除课程所有成员 def delete_all_members - if self.members && self.members.count > 0 - me, mr = Member.table_name, MemberRole.table_name - connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.course_id = #{id})") - Member.delete_all(['course_id = ?', id]) - end + CourseMember.delete_all(['course_id = ?', id]) + # if self.members && self.members.count > 0 + # me, mr = Member.table_name, MemberRole.table_name + # connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.course_id = #{id})") + # Member.delete_all(['course_id = ?', id]) + # end end # 创建课程模块 diff --git a/app/models/graduation_group.rb b/app/models/graduation_group.rb index 12570681..f0cd21e7 100644 --- a/app/models/graduation_group.rb +++ b/app/models/graduation_group.rb @@ -2,6 +2,7 @@ class GraduationGroup < ActiveRecord::Base belongs_to :course belongs_to :user has_many :members + has_many :course_members has_one :graduation_task_group_assignation, dependent: :destroy has_many :graduation_work_comment_assignations, dependent: :destroy attr_accessible :name, :user_id, :course_id