Alfredo Rico Moros
2008-Nov-23 19:07 UTC
Possible bug on find method with :select attribute and aggregate functions...
Hi to everyboy.. I need your help in order to know if I get wrong.. I have this migration file: class CreateSpecifications < ActiveRecord::Migration def self.up create_table :specifications do |t| t.string :tolerancia t.integer :umbral t.timestamps end end def self.down drop_table :specifications end end I put some data by mean of script/console Specification.create(:umbral => 33, :tolerancia => ''alta'') Specification.create(:umbral => 23, :tolerancia => ''alta'') Specification.create(:umbral => 12, :tolerancia => ''baja'') Specification.create(:umbral => 33, :tolerancia => ''baja'') Then when I run the following statement Specification.find(:all, :select => ''tolerancia, sum(umbral) as total'', :group => ''tolerancia'') I get the following: [#<Specification tolerancia: "alta">, #<Specification tolerancia: "baja">] Where is my total field??? How could I get it??? Besides, whit the following statement:>> Specification.find(:first, :select => ''now() as ahora'')=> #<Specification > Where is my field ''ahora''? Thanks in advanced by your help... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Nov-23 21:04 UTC
Re: Possible bug on find method with :select attribute and aggregate functions...
On 23 Nov 2008, at 19:07, Alfredo Rico Moros <alfredorico-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi to everyboy.. I need your help in order to know if I get wrong.. > > I have this migration file: > > class CreateSpecifications < ActiveRecord::Migration > def self.up > create_table :specifications do |t| > t.string :tolerancia > t.integer :umbral > > t.timestamps > end > end > > def self.down > drop_table :specifications > end > end > > I put some data by mean of script/console > Specification.create(:umbral => 33, :tolerancia => ''alta'') > Specification.create(:umbral => 23, :tolerancia => ''alta'') > Specification.create(:umbral => 12, :tolerancia => ''baja'') > Specification.create(:umbral => 33, :tolerancia => ''baja'') > > Then when I run the following statement > Specification.find(:all, :select => ''tolerancia, sum(umbral) as > total'', :group => ''tolerancia'') > > I get the following: > [#<Specification tolerancia: "alta">, #<Specification tolerancia: > "baja">] > > Where is my total field??? How could I get it??? >The default display for activerecord objects only shows attributes corresponding to columns on the table. It''s there - just not displayed. Call the total method to read it ( although in this case i''d just use the sum method instead of find) Fred> > Besides, whit the following statement: >>> Specification.find(:first, :select => ''now() as ahora'') > => #<Specification > > > Where is my field ''ahora''? >Same as above> > Thanks in advanced by your help... > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Alfredo Rico Moros
2008-Nov-23 22:30 UTC
Re: Possible bug on find method with :select attribute and aggregate functions...
Yes!! You are right!! Thanks a lot!! On Nov 24, 4:04 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 23 Nov 2008, at 19:07, Alfredo Rico Moros <alfredor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > > > Hi to everyboy.. I need your help in order to know if I get wrong.. > > > I have this migration file: > > > class CreateSpecifications < ActiveRecord::Migration > > def self.up > > create_table :specifications do |t| > > t.string :tolerancia > > t.integer :umbral > > > t.timestamps > > end > > end > > > def self.down > > drop_table :specifications > > end > > end > > > I put some data by mean of script/console > > Specification.create(:umbral => 33, :tolerancia => ''alta'') > > Specification.create(:umbral => 23, :tolerancia => ''alta'') > > Specification.create(:umbral => 12, :tolerancia => ''baja'') > > Specification.create(:umbral => 33, :tolerancia => ''baja'') > > > Then when I run the following statement > > Specification.find(:all, :select => ''tolerancia, sum(umbral) as > > total'', :group => ''tolerancia'') > > > I get the following: > > [#<Specification tolerancia: "alta">, #<Specification tolerancia: > > "baja">] > > > Where is my total field??? How could I get it??? > > The default display for activerecord objects only shows attributes > corresponding to columns on the table. It''s there - just not > displayed. Call the total method to read it ( although in this case > i''d just use the sum method instead of find) > > Fred > > > > > Besides, whit the following statement: > >>> Specification.find(:first, :select => ''now() as ahora'') > > => #<Specification > > > > Where is my field ''ahora''? > > Same as above > > > Thanks in advanced by your help...--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---