I have a very simple find call…
@assets = Asset.find(:all, :group => ‘asset_type_id’, :order => “name”)
I have 3 Asset objects in my database, all of which have asset_type_id
equal to 1. Why does this query only return 1 object?
I have a very simple find call…
@assets = Asset.find(:all, :group => ‘asset_type_id’, :order => “name”)
I have 3 Asset objects in my database, all of which have asset_type_id
equal to 1. Why does this query only return 1 object?
I have a very simple find call…
@assets = Asset.find(:all, :group => ‘asset_type_id’, :order => “name”)I have 3 Asset objects in my database, all of which have asset_type_id
equal to 1. Why does this query only return 1 object?
Get a good MySQL book to figure out what’s happening. The :group =>
‘asset_type_id’ call generates the SQL clause “GROUP BY
asset_type_id”. Use this when you want a SUMMARY of all the fields
with a particular value of asset_type_id. So for each value of
asset_type_id, you get ONE record. Usually you’ll also want a COUNT,
SUM, AVERAGE, or other summary function returned with this record.
OK, after reading your post I found another passage in the Rails book
about it. I was under the mistaken impression that it sorted them by
group.
Thanks.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs