ok so I am trying to do something like the below to order by :joins (I know the below won''t work)...the only solution that I can fathom is using something like find_by_sql - but I certainly would prefer a simpler method...any suggestions? User.find(:all, :joins => :deals, :group => ''rev'', :conditions => [''saledate >= ? AND saledate <= ?'', Time.now.at_beginning_of_month, Time.now.at_end_of_month], :order => "deals.rev.sum DESC") Thanks Sean --~--~---------~--~----~------------~-------~--~----~ 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 Mar 11, 10:30 pm, esdevs <seanpdev...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ok so I am trying to do something like the below to order by :joins (I > know the below won''t work)...the only solution that I can fathom is > using something like find_by_sql - but I certainly would prefer a > simpler method...any suggestions? > > User.find(:all, :joins => :deals, :group => ''rev'', :conditions => > [''saledate >= ? AND saledate <= ?'', Time.now.at_beginning_of_month, > Time.now.at_end_of_month], :order => "deals.rev.sum DESC") >I''m not entirely sure what you''re doing - :order has to be a valid sql order clause, so order by any column from any of your joined tables, or an sql expression is fine (:eg :order => "SUM(something)" should be ok, although you might need the expression in your order clause to be part of the select clause too). Fred> Thanks > > Sean--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
so to clarify - I am trying to order by the sum of the items in a column in a joined table between a certain date range. On Mar 11, 7:06 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 11, 10:30 pm, esdevs <seanpdev...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > ok so I am trying to do something like the below to order by :joins (I > > know the below won''t work)...the only solution that I can fathom is > > using something like find_by_sql - but I certainly would prefer a > > simpler method...any suggestions? > > > User.find(:all, :joins => :deals, :group => ''rev'', :conditions => > > [''saledate >= ? AND saledate <= ?'', Time.now.at_beginning_of_month, > > Time.now.at_end_of_month], :order => "deals.rev.sum DESC") > > I''m not entirely sure what you''re doing - :order has to be a valid sql > order clause, so order by any column from any of your joined tables, > or an sql expression is fine (:eg :order => "SUM(something)" should be > ok, although you might need the expression in your order clause to be > part of the select clause too). > > Fred > > > > > Thanks > > > Sean--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---