Reputation: 6451
Is there something changed in Rails 4 due to which the following doesn't work as expected:
def self.top_experts(timeframe = 1.week.ago, limit = 5)
Answer.where('created_at between ? and ?', timeframe, Time.now)
.group(:user_id)
.order('sum(score) DESC')
.limit(limit)
.includes(:user)
.collect{|x| x.user}
end
For some reason it isn't updating every week (even though a manual check does show the list returned should be different).
The query is intended to return experts who have the highest rated answers in the last 7 days..
Upvotes: 0
Views: 54
Reputation: 6451
The problem was that Answer had a default_scope which was screwing up this query, so doing Answer.unscoped
fixed it.
Jesus! This appeared to be effecting many other queries as well. I guess using default_scope
is a big no-no.
Upvotes: 2