# Possible bug on find method with :select attribute and aggregate functions

**URL:** <https://www.ruby-forum.com/t/possible-bug-on-find-method-with-select-attribute-and-aggregate-functions/153955>\
**Category:** Rails\
**Created:** [November 23, 2008, 8:49pm UTC](https://www.ruby-forum.com/t/possible-bug-on-find-method-with-select-attribute-and-aggregate-functions/153955 "2008-11-23T20:49:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alfredmart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a87d85/32.png) [@alfredmart](https://www.ruby-forum.com/u/alfredmart)\
**Post date:** [November 23, 2008, 8:49pm UTC](https://www.ruby-forum.com/t/possible-bug-on-find-method-with-select-attribute-and-aggregate-functions/153955/1 "2008-11-23T20:49:04Z")

</div>

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’)  
> > =\> #

Where is my field ‘ahora’?

Thanks in advanced by your help…

---

<div class="post-metadata">

**Author:** ![alfredmart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a87d85/32.png) [@alfredmart](https://www.ruby-forum.com/u/alfredmart)\
**Post date:** [November 23, 2008, 10:05pm UTC](https://www.ruby-forum.com/t/possible-bug-on-find-method-with-select-attribute-and-aggregate-functions/153955/2 "2008-11-23T22:05:19Z")

</div>

On 23 Nov 2008, at 19:07, Alfredo Rico M. [removed\_email\_address@domain.invalid](mailto: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’)  
> > > =\> #
> 
> Where is my field ‘ahora’?

Same as above

---

<div class="post-metadata">

**Author:** ![alfredmart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a87d85/32.png) [@alfredmart](https://www.ruby-forum.com/u/alfredmart)\
**Post date:** [November 23, 2008, 11:31pm UTC](https://www.ruby-forum.com/t/possible-bug-on-find-method-with-select-attribute-and-aggregate-functions/153955/3 "2008-11-23T23:31:28Z")

</div>

Yes!! You are right!! Thanks a lot!!

On Nov 24, 4:04 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
