Created
December 17, 2010 12:51
-
-
Save clemens/744886 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 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
It's Rails 2.3, Thinking Sphinx 1.4.0, Riddle 1.2.1 and Sphinx 0.9.9 r2117.