"fake" active record attribute

I'm gonna try to be more concise:

I do a find(:group => "some_column", :select => "count(*) as
some_column_count").

I did declare in the model "attr_accessor :some_column_count", but the
some_column_count comes up as nil, even though the SQL query yields
results.

I suppose the column is nil because is not a real active record
attribute. I added some_column_count as a column in the table and the
assign from the group find works, but I find the solutin ugly.

Is there a way to add an activerecord attribute in the model behaves
the same as a normal one, only that it doesn't map to a real column?

Gabi Ge wrote:

I found attr_internal_accessor in ActiveSupport.
http://apidock.com/rails/Module/attr_internal_accessor

I put in the invoice class
attr_internal_accessor :containers_count

Still no help:

Invoice.find(:first, :select => '345 as company_id')

=> #<Invoice company_id: 345>

Invoice.find(:first, :select => '345 as containers_count')

=> #<Invoice >

I want to have containers_count from the select to be put in the
attribute containers_count in the class.

Gabi Ge wrote:

I found attr_internal_accessor in ActiveSupport.
http://apidock.com/rails/Module/attr_internal_accessor

I put in the invoice class
attr_internal_accessor :containers_count

Still no help:

Invoice.find(:first, :select => '345 as company_id')

=> #<Invoice company_id: 345>

Invoice.find(:first, :select => '345 as containers_count')

=> #<Invoice >

This display (ie the output of inspect) will never show attributes
other the columns on the table. If you want to see whether a method is
there just call it.

Fred

Frederick Cheung wrote:

Invoice.find(:first, :select => '345 as containers_count')

=> #<Invoice >

This display (ie the output of inspect) will never show attributes
other the columns on the table. If you want to see whether a method is
there just call it.

It makes no difference:

Invoice.find(:first, :select => '345 as containers_count').containers_count

=> nil

Invoice.find(:first, :select => '345 as id').id

=> 345

Frederick Cheung wrote:

>>>> Invoice.find(:first, :select => '345 as containers_count')
>> => #<Invoice >

> This display (ie the output of inspect) will never show attributes
> other the columns on the table. If you want to see whether a method is
> there just call it.

It makes no difference:>> Invoice.find(:first, :select => '345 as containers_count').containers_count
=> nil

If you've still got an attr_accessor for containers_count or anything
like that, this will stop the above from working.

Fred

Frederick Cheung wrote: