Skip to content

Commit

Permalink
Refactor Org.with_template_and_user_counts
Browse files Browse the repository at this point in the history
- To reflect the behaviour changes to  Org.with_template_and_user_counts (commits 6708697 and d335d4d), the scope has been renamed to Org.with_template_count_and_associations_check).
- joins('LEFT OUTER JOIN templates ON orgs.id = templates.org_id') has been replaced with left_outer_joins(:templates)
  • Loading branch information
aaronskiba committed Jun 25, 2024
1 parent d335d4d commit aa99f2f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/paginable/orgs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def index
authorize(Org)
paginable_renderise(
partial: 'index',
scope: Org.with_template_and_user_counts,
scope: Org.with_template_count_and_associations_check,
query_params: { sort_field: 'orgs.name', sort_direction: :asc },
format: :json
)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/super_admin/orgs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OrgsController < ApplicationController
def index
authorize Org
render 'index', locals: {
orgs: Org.with_template_and_user_counts.page(1)
orgs: Org.with_template_count_and_associations_check.page(1)
}
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/org.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ def self.default_orgs
}

# Scope used in several controllers
scope :with_template_and_user_counts, lambda {
joins('LEFT OUTER JOIN templates ON orgs.id = templates.org_id')
scope :with_template_count_and_associations_check, lambda {
left_outer_joins(:templates)
.group('orgs.id')
.select("orgs.*,
count(distinct templates.family_id) as template_count,
Expand Down

0 comments on commit aa99f2f

Please sign in to comment.