I have a error that I can’t find the solution.
When I run:
Week.find(1).results.sum('box')
A get a SUM of column box an it works perfect!
But when I apply a filter in it:
Week.find(1).results.find(:all, :joins => [:seller],:conditions => ['sellers.user_id = ?', 1]).sum('caixas')
I get a error NoMethodError: undefined method '+' for #<Result:0x103239e58>
The object returned is the same I print It on console and don’t see anything wrong.
Somebody knows something about it?
Tks!
ActiveRecord#sumis an ActiveRecord method.The first case works because
Week.find(1).resultsreturns an association proxy that exposes the same methods of Week class.In the second case you are calling
#sumon an Array object, not an ActiveRecord model.If you want the second case to work, you should use a scope or an association proxy.
Change
to