Skip to content

Commit be19bf3

Browse files
authored
Merge pull request #596 from maebeale/drop-unnecessary-category-association
Use visible scope instead of additional association in CategoryBlueprint
2 parents 66242aa + dfa2149 commit be19bf3

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

app/blueprints/category_blueprint.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class CategoryBlueprint < Blueprinter::Base
88
# Note we are _not_ propogating the :with_subcategories view to children.
99
# This is intentional because we don't currently have multiply
1010
# nested categories so we don't need to dig any deeper.
11-
association :visible_subcategories, name: :subcategories, blueprint: CategoryBlueprint
11+
association :subcategories, blueprint: CategoryBlueprint do |category|
12+
category.categories.visible
13+
end
1214
end
1315
end

app/blueprints/configuration_blueprint.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class ConfigurationBlueprint < Blueprinter::Base
22
association :categories, blueprint: CategoryBlueprint, view: :with_subcategories do
3-
Category.visible.roots.includes(:visible_subcategories)
3+
Category.visible.roots.includes(:categories)
44
end
55

66
association :contact_methods, blueprint: ContactMethodBlueprint do

app/models/category.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ class Category < ApplicationRecord
1010
inverse_of: :parent
1111
)
1212

13-
has_many(:visible_subcategories, -> { visible.order(:display_order, :name) },
14-
class_name: "Category",
15-
foreign_key: :parent_id,
16-
inverse_of: :parent
17-
)
18-
1913
validates :name, presence: true
2014

2115
scope :visible, -> { where(display_to_public: true) }

0 commit comments

Comments
 (0)