diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index e31c77499..92845f7b9 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -20,8 +20,8 @@ class HomeController < ApplicationController shixuns = shixuns.where(homepage_show: true) subjects = subjects.where(homepage_show: true) else - shixuns = shixuns.where(laboratory_shixuns: { homepage: true }) - subjects = subjects.where(laboratory_subjects: { homepage: true }) + shixuns = shixuns.joins(:laboratory_shixuns).where(laboratory_shixuns: { homepage: true }) + subjects = subjects.joins(:laboratory_subjects).where(laboratory_subjects: { homepage: true }) end @shixuns = shixuns.includes(:tag_repertoires, :challenges).limit(8) diff --git a/app/models/laboratory.rb b/app/models/laboratory.rb index 86d2d9f54..b72e22472 100644 --- a/app/models/laboratory.rb +++ b/app/models/laboratory.rb @@ -53,7 +53,7 @@ class Laboratory < ApplicationRecord laboratory_shixun_ids = laboratory_shixuns.pluck(:shixun_id) school_shixun_ids = Shixun.joins("join user_extensions on shixuns.user_id=user_extensions.user_id").where(user_extensions: { school_id: school_id }).pluck(:id) shixun_ids = laboratory_shixun_ids + school_shixun_ids - Shixun.joins(:laboratory_shixuns).where(id: shixun_ids.uniq) + Shixun.where(id: shixun_ids.uniq) else Shixun.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: id }) end @@ -66,7 +66,7 @@ class Laboratory < ApplicationRecord laboratory_subject_ids = laboratory_subjects.pluck(:subject_id) school_subject_ids = Subject.joins("join user_extensions on subjects.user_id=user_extensions.user_id").where(user_extensions: { school_id: school_id }).pluck(:id) subject_ids = laboratory_subject_ids + school_subject_ids - Subject.joins(:laboratory_subjects).where(id: subject_ids.uniq) + Subject.where(id: subject_ids.uniq) else Subject.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: id }) end