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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Karuppan < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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 > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Karuppan <-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Karuppan < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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... > > 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 Karuppan < > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 22 Aug 2008, at 23:56, Chinna Karuppan 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> > > 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 Karuppan < > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---