mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user