-
-
Save sld/2028522 to your computer and use it in GitHub Desktop.
the query selects all ids from the full branch from the nested set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product | |
define_index do | |
# ... | |
has %( | |
( | |
SELECT GROUP_CONCAT(IFNULL(parent.`id`, '0') SEPARATOR ',') | |
FROM `categories` AS node, | |
`categories` AS parent | |
WHERE node.`merchant_id` = `products`.`merchant_id` AND | |
parent.`merchant_id` = `products`.`merchant_id` AND | |
node.`lft` BETWEEN parent.`lft` AND parent.`rgt` AND node.`id` = `category_id` | |
ORDER BY parent.`lft` | |
) | |
), :source => :query, :type => :multi, :as => :category_ids, :facet => true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment