Hi all, is just my fault.. or I can''t write an having caluse for a group in a named scope? °_° i.e. named_scope :last_year_best_buyers, :joins => :invoices, :conditions => {"invoices.closed" => true, "invoices.issued_on" => 1.years.ago..Date.today}, :group => "customers.id", :having => "SUM (invoices.taxable_income) > 15000" Calling Customer.last_year_best_buyers, leads to a: ArgumentError: Unknown key(s): having How can I specify an having clause (the only way I know to filter results using aggregate functions, ain''t it)? thanks G. --~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Well... I always can specify it on the group clause.. but it doesn''t look so clean to me (esp. since the find method has the having clause... °_°) named_scope :last_year_best_buyers, :joins => :invoices, :conditions => {"invoices.closed" => true, "invoices.issued_on" => 1.years.ago..Date.today}, :group => "customers.id HAVING SUM (invoices.taxable_income) > 15000" G. On 12 Feb, 12:57, Gabriele Tassoni <gabriele.tass...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > is just my fault.. or I can''t write an having caluse for a group in a > named scope? °_° > > i.e. > > named_scope :last_year_best_buyers, :joins => :invoices, :conditions > => {"invoices.closed" => true, "invoices.issued_on" => > 1.years.ago..Date.today}, :group => "customers.id", :having => "SUM > (invoices.taxable_income) > 15000" > > Calling Customer.last_year_best_buyers, leads to a: > > ArgumentError: Unknown key(s): having > > How can I specify an having clause (the only way I know to filter > results using aggregate functions, ain''t it)? > > thanks > G.--~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Another problem with having to specify the HAVING in the group key.. is that it looks like it would lead to errors when sequencing multiple named_scopes, i.e.: Customer.last_year_best_buyers.with_active_account But I have to investigate more on this... G. --~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
are you running rails 2.3 or higher? --~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12 Feb, 13:13, MaD <mayer.domi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> are you running rails 2.3 or higher?no, I''m not, I''m using rails 2.2.2... (the current stable, I believe...) --~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
i may be wrongv but i think :having in scopes is new to rails 2.3 --~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
quote changelog: *2.3.0/3.0* * Add :having as a key to find and the relevant associations. [miloops] --~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12 Feb, 14:18, MaD <mayer.domi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> quote changelog: > *2.3.0/3.0* > * Add :having as a key to find and the relevant associations.Thank you.. ^_^ I was guessing about it since your first post.. now I just hobe rail 2.3 won''t brake too much things, it''s never good to have to switch framework version in the middle of an app development! ^_^ G. --~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hmmmm! Even worse... named_scopes completely skip the :order key if there''s a HAVING clause.. °_° I thought I could have used wht I proposed at 13:00, but the named scope didn''t used the group key at all to find the resultset... sic... Quite annoying, I''m really hoping 2.3 won''t break too much compatibility with 2.2.2 code.. On 12 Feb, 14:45, Gabriele Tassoni <gabriele.tass...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12 Feb, 14:18, MaD <mayer.domi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > quote changelog: > > *2.3.0/3.0* > > * Add :having as a key to find and the relevant associations. > > Thank you.. ^_^ I was guessing about it since your first post.. now I > just hobe rail 2.3 won''t brake too much things, it''s never good to > have to switch framework version in the middle of an app development! > ^_^ > > G.--~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12 Feb, 17:08, Gabriele Tassoni <gabriele.tass...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hmmmm! Even worse... named_scopes completely skip the :order key ifObviously referencing the :group key, not the :order one... --~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---