FIX: Load subcategories through CategoryList (#26297)
When "lazy load categories" is enabled and parent_category_id was set, the query fetching categories contained a contradiction filtering both by parent_category_id and parent_category_id = NULL.
This commit is contained in:
parent
e59ba8e297
commit
4cdf5f2cea
|
@ -140,7 +140,7 @@ class CategoryList
|
|||
|
||||
query = self.class.order_categories(query)
|
||||
|
||||
if @guardian.can_lazy_load_categories?
|
||||
if @guardian.can_lazy_load_categories? && @options[:parent_category_id].blank?
|
||||
page = [1, @options[:page].to_i].max
|
||||
query =
|
||||
query
|
||||
|
@ -154,7 +154,7 @@ class CategoryList
|
|||
|
||||
@categories = query.to_a
|
||||
|
||||
if @guardian.can_lazy_load_categories?
|
||||
if @guardian.can_lazy_load_categories? && @options[:parent_category_id].blank?
|
||||
categories_with_rownum =
|
||||
Category
|
||||
.secured(@guardian)
|
||||
|
|
|
@ -437,5 +437,13 @@ RSpec.describe CategoryList do
|
|||
category.id,
|
||||
)
|
||||
end
|
||||
|
||||
context "with parent_category_id" do
|
||||
it "returns subcategories" do
|
||||
category_list = CategoryList.new(Guardian.new(user), parent_category_id: category.id)
|
||||
|
||||
expect(category_list.categories.size).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue