This project is archived and is in readonly mode.

#6656 new
Ben Fyvie

Batch processing #find_each and #find_in_batches causes object references to break

Reported by Ben Fyvie | March 30th, 2011 @ 11:38 PM

While trying to implement batch processing to alleviate memory bloat from a monolithic copy routine I discovered that I am unable to reference an ActiveRecord object via a belongs_to relationship even though the object id is set. Here is a basic example of what I'm talking about (within the context of batch processing):

my_comment = my_post.comments.create(:body => 'hello world')

=> 1
=> nil

=> nil

I've attached a patch that adds a test for the issue, but I can't for the life of me figure out why it is happening. If the batch processing is removed (call #each instead of #find_each) then the problem goes away.

No comments found

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket