FIX: Make find_by_slug_path work with default slugs (#11501)

Default slugs are generated by adding '-category' to category ID.
This commit is contained in:
Bianca Nenciu
2020-12-18 16:05:01 +02:00
committed by GitHub
parent 142e0ae062
commit 806f05f851
4 changed files with 43 additions and 10 deletions

View File

@@ -801,10 +801,13 @@ class Category < ActiveRecord::Base
query =
slug_path.inject(nil) do |parent_id, slug|
Category.where(
slug: slug,
parent_category_id: parent_id,
).select(:id)
category = Category.where(slug: slug, parent_category_id: parent_id)
if match_id = /^(\d+)-category/.match(slug).presence
category = category.or(Category.where(id: match_id[1], parent_category_id: parent_id))
end
category.select(:id)
end
Category.find_by_id(query)