ok so i am trying to order the results by the total size in a desc order, here is what i have so far and its not working def show @reports = Report.find(:all, :group => ''user_id'', :order => ''user_id.size desc'' ) end anybody know how to go about doing this --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Wed, Jan 21, 2009 at 11:54 AM, Dan Paul <danpaul01-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > ok so i am trying to order the results by the total size in a desc > order, here is what i have so far and its not working > > def show > @reports = Report.find(:all, :group => ''user_id'', :order => > ''user_id.size desc'' ) > end > > anybody know how to go about doing thisHi, it seems that you''re trying to access an attribute of a User table called size and this isn''t possible with the above. Thus, you''ll need to do something like the following: Report.all( :joins => :user, :group => "user_id", :order => "size desc" ) The key thing here is to use :joins to access the users table within the query. This allows one to access the fields in the query without displaying the data of that attribute. Good luck, -Conrad --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Awesome, thanks for the reply i shall give it a try On Jan 21, 2:35 pm, Conrad Taylor <conra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, Jan 21, 2009 at 11:54 AM, Dan Paul <danpau...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > ok so i am trying to order the results by the total size in a desc > > order, here is what i have so far and its not working > > > def show > > @reports = Report.find(:all, :group => ''user_id'', :order => > > ''user_id.size desc'' ) > > end > > > anybody know how to go about doing this > > Hi, it seems that you''re trying to access an attribute of a User table > called size and > this isn''t possible with the above. Thus, you''ll need to do something like > the following: > > Report.all( :joins => :user, :group => "user_id", :order => "size desc" ) > > The key thing here is to use :joins to access the users table within the > > query. This allows one to access the fields in the query without displaying > > the data of that attribute. > > Good luck, > > -Conrad--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---