Commit cf5a660f7707bd487a7bd7e8e05027236ec4e623
1 parent
06a34206
Exists in
master
and in
22 other branches
ActionItem514: improved category finder to use product categorization join table
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2200 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
1 changed file
with
4 additions
and
6 deletions
Show diff stats
app/models/category_finder.rb
@@ -59,16 +59,14 @@ class CategoryFinder | @@ -59,16 +59,14 @@ class CategoryFinder | ||
59 | def options_for_find(klass, options={}, date_range = nil) | 59 | def options_for_find(klass, options={}, date_range = nil) |
60 | if defined? options[:product_category] | 60 | if defined? options[:product_category] |
61 | prod_cat = options.delete(:product_category) | 61 | prod_cat = options.delete(:product_category) |
62 | - # FIXME this is SLOOOOW | ||
63 | - prod_cat_ids = prod_cat.map_traversal(&:id) if prod_cat | ||
64 | end | 62 | end |
65 | 63 | ||
66 | case klass.name | 64 | case klass.name |
67 | when 'Comment' | 65 | when 'Comment' |
68 | {:joins => 'inner join articles_categories on articles_categories.article_id = comments.article_id', :conditions => ['articles_categories.category_id = (?)', category_id]}.merge!(options) | 66 | {:joins => 'inner join articles_categories on articles_categories.article_id = comments.article_id', :conditions => ['articles_categories.category_id = (?)', category_id]}.merge!(options) |
69 | when 'Product' | 67 | when 'Product' |
70 | - if prod_cat_ids | ||
71 | - {:joins => 'inner join categories_profiles on products.enterprise_id = categories_profiles.profile_id', :conditions => ['categories_profiles.category_id = (?) and products.product_category_id in (?)', category_id, prod_cat_ids]}.merge!(options) | 68 | + if prod_cat |
69 | + {:joins => 'inner join categories_profiles on products.enterprise_id = categories_profiles.profile_id inner join product_categorizations on (product_categorizations.product_id = products.id)', :conditions => ['categories_profiles.category_id = (?) and product_categorizations.category_id = (?)', category_id, prod_cat.id]}.merge!(options) | ||
72 | else | 70 | else |
73 | {:joins => 'inner join categories_profiles on products.enterprise_id = categories_profiles.profile_id', :conditions => ['categories_profiles.category_id = (?)', category_id]}.merge!(options) | 71 | {:joins => 'inner join categories_profiles on products.enterprise_id = categories_profiles.profile_id', :conditions => ['categories_profiles.category_id = (?)', category_id]}.merge!(options) |
74 | end | 72 | end |
@@ -83,8 +81,8 @@ class CategoryFinder | @@ -83,8 +81,8 @@ class CategoryFinder | ||
83 | end | 81 | end |
84 | {:joins => 'inner join articles_categories on (articles_categories.article_id = articles.id)', :conditions => conditions}.merge!(options) | 82 | {:joins => 'inner join articles_categories on (articles_categories.article_id = articles.id)', :conditions => conditions}.merge!(options) |
85 | when 'Enterprise' | 83 | when 'Enterprise' |
86 | - if prod_cat_ids | ||
87 | - {:joins => 'inner join categories_profiles on (categories_profiles.profile_id = profiles.id) inner join products on (products.enterprise_id = profiles.id)', :conditions => ['categories_profiles.category_id = (?) and products.product_category_id in (?)', category_id, prod_cat_ids]}.merge!(options) | 84 | + if prod_cat |
85 | + {:joins => 'inner join categories_profiles on (categories_profiles.profile_id = profiles.id) inner join products on (products.enterprise_id = profiles.id) inner join product_categorizations on (product_categorizations.product_id = products.id)', :conditions => ['categories_profiles.category_id = (?) and product_categorizations.category_id = (?)', category_id, prod_cat.id]}.merge!(options) | ||
88 | else | 86 | else |
89 | {:joins => 'inner join categories_profiles on (categories_profiles.profile_id = profiles.id)', :conditions => ['categories_profiles.category_id = (?)', category_id]}.merge!(options) | 87 | {:joins => 'inner join categories_profiles on (categories_profiles.profile_id = profiles.id)', :conditions => ['categories_profiles.category_id = (?)', category_id]}.merge!(options) |
90 | end | 88 | end |