[FIX]project category correct projects_count

This commit is contained in:
vilet.yy 2021-03-01 16:23:29 +08:00
parent cc978c8dea
commit 2969afd333
3 changed files with 4 additions and 6 deletions

View File

@ -6,8 +6,6 @@ class ProjectCategoriesController < ApplicationController
end
def group_list
# @project_categories = ProjectCategory.where('projects_count > 0').order(projects_count: :desc)
@project_categories = ProjectCategory.eager_load(:projects)
.where(projects: {is_public: true})
@project_categories = ProjectCategory.where('projects_count > 0').order(projects_count: :desc)
end
end

View File

@ -116,7 +116,7 @@ class Project < ApplicationRecord
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
scope :recommend, -> { visible.project_statics_select.where(recommend: true) }
scope :secret_and_visible, -> {joins(:license).where("licenses.is_secret = TRUE OR projects.is_public = TRUE")}
scope :secret_and_visible, -> {left_outer_joins(:license).where("licenses.is_secret = TRUE OR projects.is_public = TRUE")}
delegate :is_secret, to: :license, allow_nil: true

View File

@ -1,6 +1,6 @@
json.array! @project_categories do |category|
hidden_projects = category.projects.joins(:license).where(is_public: false, licenses: {is_secret: false})
json.id category.id
json.name category.name
# json.projects_count category.projects_count
json.projects_count category.projects.size
json.projects_count category.projects_count - hidden_projects.size
end