Sha256: 422ab2d85e132630b62cf151b66c57131e1612130fce15c4d3f1b81b248ba027
Contents?: true
Size: 1.5 KB
Versions: 3
Compression:
Stored size: 1.5 KB
Contents
module EducodeSales class Teacher < ApplicationRecord has_many :activity_teachers has_many :activities, through: :activity_teachers has_many :teacher_follows, dependent: :destroy has_many :operation_plans, dependent: :destroy has_many :course_subjects, dependent: :destroy belongs_to :department, optional: true belongs_to :staff belongs_to :user, optional: true belongs_to :follow_up, counter_cache: true, optional: true validates :user_id, uniqueness: { allow_blank: true, message: '已存在老师列表'} def teacher_used_of_department if user_id.present? user_ids = User.joins(:user_extension).where(user_extensions: {department_id: self.department_id, identity: 0}).pluck(:id) course_ids = CourseMember.where(role: "CREATOR", user_id: user_ids).pluck(:course_id) if course_ids.present? course_members = CourseMember.joins(course: :practice_homework_shixuns).where(course_id: course_ids).group("course_id").having("COUNT(homework_commons_shixuns.id) > 100 AND COUNT(course_members.user_id) > 30").select("COUNT(*) AS count") course_members.present? ? course_members[0]['count'] : 0 else 0 end else 0 end end def students_count if user_id.present? course_ids = CourseMember.where.not(role: "STUDENT").where(user_id: user_id).pluck(:course_id) CourseMember.where(course_id: course_ids, role: "STUDENT").count else 0 end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
educode_sales-0.2.0 | app/models/educode_sales/teacher.rb |
educode_sales-0.1.8 | app/models/educode_sales/teacher.rb |
educode_sales-0.1.7 | app/models/educode_sales/teacher.rb |