How do I start a transaction in a controller, then attempt to save multiple models that have no relation to each other? If anything fails, obviously I wish to rollback, and if everything worked then commit.
I guess my question is which model do I start the transaction on?
$datasource = $this->Car->getDataSource();
$datasource->begin($this->Car);
$car = $this->Car->save();
$dog = $this->Dog->save();
$house = $this->House->save();
if ($car && $dog && $house) {
$datasource->commit($this->Car);
} else {
$datasource->rollback($this->Car);
}
Will this work to ensure Dog and House save as well as the Car? i.e. Does it matter which model the transaction is started on?