# ActiveRecord fails to update without a pause

**URL:** <https://www.ruby-forum.com/t/activerecord-fails-to-update-without-a-pause/177110>\
**Category:** Rails\
**Created:** [October 11, 2009, 11:06pm UTC](https://www.ruby-forum.com/t/activerecord-fails-to-update-without-a-pause/177110 "2009-10-11T23:06:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tachekent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7993a0/32.png) [@tachekent](https://www.ruby-forum.com/u/tachekent)\
**Post date:** [October 11, 2009, 11:06pm UTC](https://www.ruby-forum.com/t/activerecord-fails-to-update-without-a-pause/177110/1 "2009-10-11T23:06:58Z")

</div>

Hi there,  
I’m having a strange issue with active record in 2.3.2 development env  
whereby an update\_ attribute within a loop only gets written to the db  
if I write (anything) to the logfile, or set a sleep of somewhere  
between 0.5 and 1 second.

The function is a remotely called drag and drop list sorter:

def sort  
i = 1  
params[:cv].each {  
|id|  
if cv\_type = current\_user.cv\_types.find(id)  
if cv\_type.update\_attribute(:position, i)  
sleep 1 # if I remove this it doesn’t work any more  
i = i+1  
end  
end  
}  
render :nothing =\> true  
end

and from the logfile without the sleep command:

CvType Load (0.2ms) SELECT \* FROM `cv_types` WHERE  
(`cv_types`.`id` = 5 AND (`cv_types`.user\_id = 1)) ORDER BY position  
SQL (0.1ms) BEGIN  
SQL (0.1ms) COMMIT  
CvType Load (0.4ms) SELECT \* FROM `cv_types` WHERE  
(`cv_types`.`id` = 4 AND (`cv_types`.user\_id = 1)) ORDER BY position  
SQL (0.1ms) BEGIN  
SQL (0.1ms) COMMIT

and then with the sleep command:

CvType Load (0.5ms) SELECT \* FROM `cv_types` WHERE  
(`cv_types`.`id` = 4 AND (`cv_types`.user\_id = 1)) ORDER BY position  
SQL (0.1ms) BEGIN  
CvType Update (0.2ms) UPDATE `cv_types` SET `position` = 1 WHERE  
`id` = 4  
SQL (0.5ms) COMMIT  
CvType Load (0.4ms) SELECT \* FROM `cv_types` WHERE  
(`cv_types`.`id` = 5 AND (`cv_types`.user\_id = 1)) ORDER BY position  
SQL (0.1ms) BEGIN  
CvType Update (0.2ms) UPDATE `cv_types` SET `position` = 2 WHERE  
`id` = 5  
SQL (0.6ms) COMMIT

Surely that isn’t normal?  
I don’t mind writing to the logfile, but it seems that something else  
is afoot. and I can’t think what.

Any insight would be very helpful.  
thanks,  
dorian
