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?
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.
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
> 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.