ActiveRecord Save is not saving.

I am having a strange problem. I am trying to update a bunch of records like this

a.each do |a| b = Company.find_by_id(a.company_id) b.col_name = Time.now b.save

end

after I run this, I check the DB and the column “col_name” is indeed updated. However, if I check the DB 5-10 minutes later, all changes are gone. I’ve tried update_attribute, same problem.

Any idea what I am doing wrong?

thanks,

"eduard" wrote:

I am having a strange problem. I am trying to update a bunch of records like this

a.each do |a| b = Company.find_by_id(a.company_id) b.col_name = Time.now b.save end

after I run this, I check the DB and the column "col_name" is indeed updated. However, if I check the DB 5-10 minutes later, all changes are gone. I've tried update_attribute, same problem.

Try checking your configuration and verify that database auto-commit is turned on.

hth,

Long

Long,

I checked, my autommit is set to 1. I am using MySQL. Any idea what else might be wrong?

Thanks for your help, e

Does anone know what else can be wrong with my DB? Every once in a while my Updates don’t get committed. The application was working fine all morning, but just now one update got rolled back again. My @@autocommit is enabled, I am not using any transactions, it’s a simple update.

Thanks,

It appears your code is not checking the result of .save to see whether validation failed.

jeremy

I check save and it works fine. I check the DB after I run update and the records are updated (most of the time). However, every once in a while, if I check the table that was updated 5 minutes later, all changes are rolled back. I realized that it’s the issue with MySQL, not Rails. Is my MySQL missing some crucial configuration that I am not aware of?. I am using MySQL 5, InnoDB and my @@autocommit is enabled. I posted a question on mysql.com several days ago but never got a single response.

Any help would be greately appreciated.

thanks

Zach,

Yes, I can reproduce this error within MySQL client. So, it’s defintely not a Rails issue. I can only reproduce this error a few times a day, usually it works fine. I am running Version: ‘5.0.22’ on FC 5 and my @@autocommit is enabled.

here’s my my.cnf file