Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the automatic transaction option in CakePHP is called "atomic"?

I do not understand the meaning of the word "atomic". For example:

$conn = $this->ArticlesTable->connection();
$articles->save($entity, ['atomic' => false]); // <-- here
$conn->commit();

Should it not be be "autocommit" instead?

like image 489
Paulo Alexandre Chaves Pinto Avatar asked Dec 19 '22 10:12

Paulo Alexandre Chaves Pinto


1 Answers

You're actually turning on/off "atomic" transactions, not "automatic" transactions.

"Atomic" is the correct term:

An atomic transaction is an indivisible and irreducible series of database operations such that either all occur, or nothing occurs. A guarantee of atomicity prevents updates to the database occurring only partially, which can cause greater problems than rejecting the whole series outright.

-Wikipedia: Atomicity

The key there is "...such that either ALL occur, or NOTHING occurs."

When atomic is false (off), and you run a save that requires more than one query, it will run each individually and could be successful on some, but not others.

When atomic is true (on), and you run a save that requires more than one query, it will process them as a single transaction, and either complete all successfully or fail all completely. No partial saves/updates.

like image 168
Dave Avatar answered Apr 28 '23 18:04

Dave