f3-factory / fatfree-core

Fat-Free Framework core library
GNU General Public License v3.0
207 stars 88 forks source link

Feature request: rollback a transaction left object in a valid state #284

Open kumy opened 5 years ago

kumy commented 5 years ago

(Moved from https://github.com/ikkez/f3-cortex/issues/90)

When we rollback a transaction, the previously saved objects stay in a valid state (valid per use of dry()/valid() functions).

I would have expected the dry() function to return true.

here is a little example:

$f3->get('DB')->begin();
$move = new Move();
$move->comment = 'Some comment';

var_dump(move->dry());
$move->save();
var_dump(move->dry());

$f3->get('DB')->rollback();
var_dump(move->dry());

This outputs:

bool(true)
bool(false)
bool(false)

But I expect it to return:

bool(true)
bool(false)
bool(true)
xfra35 commented 5 years ago

That's not possible since the DB class is not aware of all the mappers relying on it.

Just call reset() when the rollback is successful:

$f3->get('DB')->rollback() && $move->reset();