0

I have a Person model which has attributes name and address.I am doing this:

ActiveRecord::Base.transaction do
Person.where(:id=>[1]).update_all(:address => "Newyork") #1st update  
Person.where(:id=>[2]).update_all(:address1 => "Newyork") #2nd update  
end 

I intentionally put address1 here which is not the property/attribute of model Person. As address1 is not the property of this model so 2nd update should get failed and 1st update should get rollbacked too.

But in my case, 2nd update is getting failed but 1st update is not rolling back.Why?

Weafs.py
  • 22,731
  • 9
  • 56
  • 78
Shobhit_Geek
  • 591
  • 9
  • 22
  • 1
    What database are you using? E.g. MySql with MyISAM storage engine doesn't support transactions. – koffeinfrei Aug 29 '14 at 20:22
  • Can you show the error message? – pangpang Aug 30 '14 at 03:05
  • @koffeinfrei : I am using mysql. @liuzxc : I am getting error message: Mysql2::Error: Unknown column 'persons.address1' in 'field list': UPDATE `persons` SET `persons`.`address1` = 'Newyork' WHERE `persons`.`id` in (2) – Shobhit_Geek Aug 30 '14 at 10:01
  • Can you check what storage engine you are using (`SELECT ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'your_schema' AND TABLE_NAME = 'your_table'`)? – koffeinfrei Aug 30 '14 at 19:12
  • @koffeinfrei : It's InnoDB. I checked the same on my friends machine and same is happening. Can you please check this simple example at your end and figure out what the issue is? – Shobhit_Geek Aug 31 '14 at 09:59
  • I'm currently on the way... Can you try to reproduce the behaviour with a different database, e.g. postgres? – koffeinfrei Sep 08 '14 at 19:51

0 Answers0