Updating objects in arrays

Perhaps this is a Rails issue. However, I need to first determine whether I simply am missing something about updating members of an array.

I have an array of 10 ActiveRecord objects. I wish to iterate over the array and update an attribute. When I do this the underlying table row changes but the object in the array frequently does not. For example:

count = 0
current_entries.each do |entry|
puts( entry.object_id )
puts( current_entries[count].object_id )
puts( “***” )
puts( entry.lock_version )
entry = set_customs_entry_status_for( entry, status )
puts( entry.lock_version )
current_entries[ count ] = entry
puts( current_entries[ count ] = entry )
end

gives:
58380880
58380880

Perhaps this is a Rails issue. However, I need to first determine whether I
simply am missing something about updating members of an array.

I have an array of 10 ActiveRecord objects. I wish to iterate over the
array and update an attribute. When I do this the underlying table row
changes but the object in the array frequently does not. For example:

  count = 0
  current_entries.each do |entry|
    puts( entry.object_id )
    puts( current_entries[count].object_id )
    puts( "***" )
    puts( entry.lock_version )
    entry = set_customs_entry_status_for( entry, status )

You have not shown us set_customs_entry_status_for but it might be
informative to try a
     puts( entry.object_id )
here.

Colin

The answer to the source of the problem actually was in the object_ids
given in my original message. I just did not see what my data was
telling me. There is a contingent update on entry when a different
model is updated. This was creating the stale record issue because
the table was being updated via a different set of objects from those
under examination in the test.

You need to reload the object after updating it if you need to use the
updated version.

set_customs_entry_status_for( entry, status )
entry.reload