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 Abandon <[email protected]>:
>
> 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?
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>

-- 
Von meinen Mobilgerät aus gesendet

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to