From 6968039c87150def6bf21025b67ced2fc525cd4f Mon Sep 17 00:00:00 2001 From: nwb Date: Fri, 18 Jul 2014 09:55:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=BE=E7=A8=8B=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E8=AE=A1=E7=AE=97=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/courses_helper.rb | 13 ++++++++++--- app/models/course.rb | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index b4b89bb0f..b03f6cfa1 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -104,10 +104,17 @@ module CoursesHelper garble count end - alias studentCountOrigin studentCount + # 注意:此方法有问题,速度慢且结果不准 + # alias studentCountOrigin studentCount + #def studentCount course + # count = studentCountOrigin course + #garble count + # end + + # 学生人数计算 + # add by nwb def studentCount course - count = studentCountOrigin course - garble count + course.student.count end def eventToLanguageCourse event_type, course diff --git a/app/models/course.rb b/app/models/course.rb index 1c20edb72..75bac905c 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -21,7 +21,7 @@ class Course < ActiveRecord::Base has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :homework_for_courses, :dependent => :destroy - has_many :student, :through => :students_for_courses, :source => :user + has_many :student, :class_name => 'StudentsForCourse', :source => :user has_many :course_infos, :class_name => 'CourseInfos',:dependent => :destroy has_many :enabled_modules, :dependent => :delete_all has_many :boards, :dependent => :destroy, :order => "position ASC"