Sum Method in Active Record

Hi,
How can I use the sum method in the Active Record in my normal class.I
have one helper class…I saw a webcast in which the guy was using the
method in rails in his class by just including the module that contained
the method.I don’t remember which screen cast …
But the question is can I use the include
ActiveRecord:Calculations:ClassMethods in my class and start using the
sum method on it…
THnks
Chinna

You should be able to do YourModel.sum(:column) without including
anything
special.

http://www.railsbrain.com/api/rails-2.1.0/doc/index.html?a=M001763&name=sum

On Fri, Aug 22, 2008 at 4:33 PM, Chinna K. <

my model is not backed by active record.I said my NORMAL CLASS .IT IS
NOT EXTENDING FROM ACTIVERECORD…or any class how can it use some of
the use methods available in rails…

Joe K wrote:

You should be able to do YourModel.sum(:column) without including
anything
special.

http://www.railsbrain.com/api/rails-2.1.0/doc/index.html?a=M001763&name=sum

On Fri, Aug 22, 2008 at 4:33 PM, Chinna K. <

Ohh, sorry about that.

Just an educated guess, but from skimming the source code, it looks like
it
relies pretty heavily on the rest of active record being there.
Personally,
I would just write a class method that constructs an sql query and
executes
it, which I have done before in cases where I have complex joins that
would
take active record ages to process.

rows = sql.execute(“select sum(column) as total from table where stuff”)
rows.each do |row|
print row[0]
end

On Fri, Aug 22, 2008 at 6:56 PM, Chinna K. <

On 22 Aug 2008, at 23:56, Chinna K. wrote:

my model is not backed by active record.I said my NORMAL CLASS .IT IS
NOT EXTENDING FROM ACTIVERECORD…or any class how can it use some of
the use methods available in rails…

If your model is not an activerecord model, then what does
YourModel.sum(:something) mean ?

Fred