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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---