Hi all, Good to see Array.wrap get added. However it doesn''t DWIM with associations:>> Array.wrap(Icp.find(16).registers)=> [[#<Register ...>]]>> Array.wrap(DisputedRead.unresolved)=> [[#<DisputedRead ...>, #<DisputedRead ...>]] ie. array-like collections and scopes aren''t getting treated as arrays and are being wrapped again. The short-term solution the coder who hit this suggested was to add a case to the #wrap: when ActiveRecord::NamedScope::Scope, ActiveRecord::Associations::AssociationCollection object.to_a But this has the effect of loading ActiveRecord from ActiveSupport, which is undesirable. Is there a better way to detect association-collection-ness? I''m thinking that it might be better to check for the #to_ary method on all objects and use that instead, without having a special case for collections/scopes. Does that sound OK? If so I''ll submit a patch. Cheers, Will --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Tue, Feb 10, 2009 at 3:29 PM, Will Bryant <will.bryant@gmail.com> wrote:> > Hi all, > > Good to see Array.wrap get added. However it doesn''t DWIM with associations: > >>> Array.wrap(Icp.find(16).registers) > => [[#<Register ...>]] > >>> Array.wrap(DisputedRead.unresolved) > => [[#<DisputedRead ...>, #<DisputedRead ...>]] > > ie. array-like collections and scopes aren''t getting treated as arrays > and are being wrapped again. > > The short-term solution the coder who hit this suggested was to add a > case to the #wrap: > > when ActiveRecord::NamedScope::Scope, > ActiveRecord::Associations::AssociationCollection > object.to_a > > But this has the effect of loading ActiveRecord from ActiveSupport, > which is undesirable. Is there a better way to detect > association-collection-ness? > > I''m thinking that it might be better to check for the #to_ary method > on all objects and use that instead, without having a special case for > collections/scopes. Does that sound OK? If so I''ll submit a patch.Yeah, good call. Please do! jeremy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
>> I''m thinking that it might be better to check for the #to_ary method >> on all objects and use that instead, without having a special case for >> collections/scopes. Does that sound OK? If so I''ll submit a patch. > > Yeah, good call. Please do!Thanks, have filed http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1935-arraywrap-handling-of-association-collections. Cheers, Will --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---