work around odd scoping bug in Rails

This commit is contained in:
Sam 2013-12-13 19:00:48 +11:00
parent 05a3c8090f
commit 1649f56529

View file

@ -114,12 +114,19 @@ class Search
end end
def category_search def category_search
# scope is leaking onto Category, this is not good and probably a bug in Rails
# the secure_category_ids will invoke the same method on User, it calls Category.where
# however the scope from the query below is leaking in to Category, this works around
# the issue while we figure out what is up in Rails
secure_category_ids
categories = Category.includes(:category_search_data) categories = Category.includes(:category_search_data)
.where("category_search_data.search_data @@ #{ts_query}") .where("category_search_data.search_data @@ #{ts_query}")
.references(:category_search_data) .references(:category_search_data)
.order("topics_month DESC") .order("topics_month DESC")
.secured(@guardian) .secured(@guardian)
.limit(@limit) .limit(@limit)
.to_a
categories.each do |c| categories.each do |c|
@results.add_result(SearchResult.from_category(c)) @results.add_result(SearchResult.from_category(c))