Forum: Ruby on Rails Possible bug on find method with :select attribute and aggregate functions...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Alfredo Rico M. (Guest)
on 2008-11-23 21:49
(Received via mailing list)
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...
Frederick C. (Guest)
on 2008-11-23 23:05
(Received via mailing list)
On 23 Nov 2008, at 19:07, Alfredo Rico M. <removed_email_address@domain.invalid>
wrote:

>
> Specification.create(:umbral => 33, :tolerancia => 'alta')
> "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
Alfredo Rico M. (Guest)
on 2008-11-24 00:31
(Received via mailing list)
Yes!! You are right!! Thanks a lot!!

On Nov 24, 4:04 pm, Frederick C. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.