Hi, Rails 3.0.3 Ruby 1.8.7 We''ve got a nested method we''re trying to update for Rails 3. However, it appears to be generating invalid sql. The old Rails 2 method worked. What am I doing wrong? # The tables in question are sites, photos, site_photos # In the Site model has_many :photos, :through => :site_photos do # Old method. This works. #def dates_with_photos # find :all, :select => ''distinct date_taken'', :order => ''date_taken'' #end # Attempt at an updated version for Rails 3. This fails. def dates_with_photos order("date_taken").select("distinct(date_taken)").all end end # Example: Site.find(5).photos.dates_with_photos # It generates invalid sql. This is the bit that''s invalid: SELECT "photos".*, distinct(date_taken) FROM "photos"; Any ideas? Regards, Dan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I am experiencing the same problem as daniel - has_many through association - get invalid sql when try to use a scope with "select distinct": basically, the "select" i specify does not override the default implicit select of the has_many join, but instead gets appended to it (as in daniel''s example) Does anyone know if this is by design, or a bug? 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Nov 19, 1:23 pm, "Alex V." <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I am experiencing the same problem as daniel > > - has_many through association > > - get invalid sql when try to use a scope with "select distinct": > basically, the "select" i specify does not override the default implicit > select of the has_many join, but instead gets appended to it (as in > daniel''s example) > > Does anyone know if this is by design, or a bug?I''m guessing bug. As of Arel 2.0.6 I''m no longer getting invalid sql, but I''m not getting valid results either. Dan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
On Dec 1, 10:43 am, Daniel Berger <djber...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 19, 1:23 pm, "Alex V." <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > I am experiencing the same problem as daniel > > > - has_many through association > > > - get invalid sql when try to use a scope with "select distinct": > > basically, the "select" i specify does not override the default implicit > > select of the has_many join, but instead gets appended to it (as in > > daniel''s example) > > > Does anyone know if this is by design, or a bug? > > I''m guessing bug. As of Arel 2.0.6 I''m no longer getting invalid sql, > but I''m not getting valid results either.Disregard, it''s still generating invalid sql. Dan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.