Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#6656

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')

my_comment.post_id 
=> 1

my_comment.post
=> nil

my_comment.reload
my_comment.post
=> 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.

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

State: new
Milestone: none
Assigned to: Pratik Pratik
Importance: none

Activity

No comments yet.