Hi
Looking at the last iteration of ZF Quickstart, i see an useful addition
with the DataMapper pattern, but i always wonder where i should put my
transactions logic.
I can't put the begin/commit into the "save"/"delete"/put-your-method-here
method because this method may be called from another 'save' method. I mean,
the Phone->delete() method can be called inside Customer->delete(), so the
possibility of finding several nested transactions calls is possible (maybe
not in this use case, but in anothers).
I don't want to put the transactions logic outside the mapper because i
think this is the place there should be, i don't think the controller's
should be aware of this stuff, so i miss a layer/something/example
somewhere.
Example:
Class CustomerMapper
{
/**
* Removes a Customer and all his phones, addresses, etc.
*/
public function delete()
{
$db->beginTransaction();
try {
// delete customer via table
...
PhoneMapper::deleteByCustomerId($id);
AddressMapper::deleteByCustomerId($id);
$db->commit();
} catch(Exception $e) {
$db->rollback();
throw new Exception('bla bla');
}
}
}
Something wrong arises when another method has CustomerMapper::delete inside
his transaction logic.
Any idea?
-------------------------------------------------------------------
Xavier Vidal Piera
Responsable Tècnic de Citrusparadis.com
[email protected]
[email protected]
610.68.41.78