Undefined method error on .sum

I have a mistake that I cannot find a solution.

When I run:

Week.find(1).results.sum('box')

A get SUM column fields and it works great!

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 an error NoMethodError: undefined method '+' for #<Result:0x103239e58>

The returned object is the same as me, I will print it on the console and do not see anything bad.

Does anyone know about this?

Tks!

+3
source share
1 answer

ActiveRecord#sum is an ActiveRecord method.

The first case works because it Week.find(1).resultsreturns an association proxy that provides the same methods of the Week class.

#sum Array, ActiveRecord. , , -.

Week.find(1).results.find(:all, :joins => [:seller],:conditions => ['sellers.user_id = ?', 1]).sum('caixas')

Week.find(1).results.scoped(:joins => [:seller], :conditions => ['sellers.user_id = ?', 1]).sum('caixas')
+3

Source: https://habr.com/ru/post/1733675/


All Articles