Transaction is not working in mysql database

Ruby/Rails/DB/PF -v => 1.8.6/2.3.2/mysql/Winxp

user.rb
class User
validates_presence_of :name
end

code 1

def destroy
User.count #=> 0
User.transaction do
User.create({:name=>“kkk”})
User.create({:name=>nil})
end
User.count #=> 1
end

why it is stored one record only even it is in side transaction block

but below code working perfectly

#code 2
def destroy
User.transaction do
begin
User.create!({:name=>“kkk”})
User.create!({:name=>nil})
rescue
end
end
end

i want to know, why the transaction is not happedned in previous code
is it behaviour of Mysql database ?
or
behaviour of Rails?

Your first code does not raise an exception and so the transaction is
not rolled back. Note the exclamation mark after create!

2009/7/8, Sniper A. [email protected]:

code 1

why it is stored one record only even it is in side transaction block
end


Von meinen Mobilgerät aus gesendet

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs