This project is archived and is in readonly mode.
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')
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.
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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>