Chris Saunders
2013-Dec-03 17:27 UTC
#find_in_batches should support returning Active Relations as well as arrays
I was directed here from the rails repo. Currently find_in_batches converts all relations into arrays<https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/batches.rb#L100> before yielding to the block. It would be nice if we could just work with relations (which are lazy if I can recall correctly) and allow the consumer to manipulate data as deemed fit. This will also allow some operations to be performed in batches (i.e. staggeringupdate_all) instead of needing to recreate the set. Looking at the code it shouldn''t be hard to implement, and I don''t mind working on the patch. I just wanted to get feedback on this before I go ahead and write up the code. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
richard schneeman
2013-Dec-03 21:43 UTC
Re: #find_in_batches should support returning Active Relations as well as arrays
Seems good, but could be a bit odd to work with. Most people will have written code that expects an Array. It seems like an AR relation behaves exactly like an array (not sure if there are known caveats here). If there aren''t any major caveats, and there''s no speed degradation and all tests pass, I say go for it. On Tue, Dec 3, 2013 at 11:27 AM, Chris Saunders < christopher.saunders@jadedpixel.com> wrote:> I was directed here from the rails repo. > > Currently find_in_batches converts all relations into arrays<https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/batches.rb#L100> before > yielding to the block. > > It would be nice if we could just work with relations (which are lazy if I > can recall correctly) and allow the consumer to manipulate data as deemed > fit. This will also allow some operations to be performed in batches (i.e. > staggeringupdate_all) instead of needing to recreate the set. > > Looking at the code it shouldn''t be hard to implement, and I don''t mind > working on the patch. I just wanted to get feedback on this before I go > ahead and write up the code. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-core+unsubscribe@googlegroups.com. > To post to this group, send email to rubyonrails-core@googlegroups.com. > Visit this group at http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/groups/opt_out. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.