I was interested in how transactions work. Your specific scenario is explained in docs . Quoting documents
. . , :
User.transaction do
User.create(username: 'Kotori')
User.transaction do
User.create(username: 'Nemu')
raise ActiveRecord::Rollback
end
end
"", "". ActiveRecord:: ROLLBACK. , .
ROLLBACK , - require_new: true. - , - . :
User.transaction do
User.create(username: 'Kotori')
User.transaction(requires_new: true) do
User.create(username: 'Nemu')
raise ActiveRecord::Rollback
end
end
"". MySQL PostgreSQL. SQLite3 version >= '3.6.8' .
. , , , true - MS-SQL. - Active Record MySQL PostgreSQL. . Dev.mysql.com/doc/refman/5.6/en/savepoint.html .