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