Neeraj Singh
2010-May-14 03:22 UTC
select method on ActiveRecord::Relation brakes enumeration
class Brake scope :good, where(:quality => ''good'') end Brake.all.select &:nil? #=> works fine Brake.good.select &:nil? #=> FAILS Last statement fails because Brake.good.select is returning ActiveRecord::Relation and not an array. I have posted a detailed discussion on ticket #4589 . https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4589-issues-with-scopesassociation-proxies-lazyenum-behavior#ticket-4589-4 Would love to hear thoughts from others. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Nicolás Sanguinetti
2010-May-14 03:31 UTC
Re: select method on ActiveRecord::Relation brakes enumeration
On Fri, May 14, 2010 at 12:22 AM, Neeraj Singh <neerajdotname@gmail.com> wrote:> class Brake > scope :good, where(:quality => ''good'') > end > > Brake.all.select &:nil? #=> works fine > Brake.good.select &:nil? #=> FAILS > > Last statement fails because Brake.good.select is returning > ActiveRecord::Relation and not an array. > > I have posted a detailed discussion on ticket #4589 . > https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4589-issues-with-scopesassociation-proxies-lazyenum-behavior#ticket-4589-4 > > Would love to hear thoughts from others.If you want to explicitly call an Array/Enumerable method on a Relation, convert it to one first, by using #to_a. I don''t think this is a problem, just something that is expectable but you should remember. Cheers, -foca> -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.