FIX: Category.find_by_slug

find_by_slug should ensure that the parent actually exists when its
looking for a parent.
This commit is contained in:
Daniel Waterworth
2019-10-15 16:39:09 +01:00
parent e83c2488a2
commit 5f5b232cde
3 changed files with 33 additions and 5 deletions

View File

@ -709,7 +709,8 @@ class Category < ActiveRecord::Base
def self.find_by_slug(category_slug, parent_category_slug = nil)
if parent_category_slug
parent_category_id = self.where(slug: parent_category_slug, parent_category_id: nil).pluck(:id).first
parent_category_id = self.where(slug: parent_category_slug, parent_category_id: nil).select(:id)
self.where(slug: category_slug, parent_category_id: parent_category_id).first
else
self.where(slug: category_slug, parent_category_id: nil).first