Hi,
Having a ponder over my data access with my mapper classes. Where I have data-centric classes (ie; an "Customer") which maps directly to a Customer record in the database, and there is an equivalent mapper. (On a tangent, I'm still unsure how to factor classes like these out as I get the impression they're considered bad-practise?).
With the mapper, there's the usual update/insert functions, but say I have a customer, which has a collection of addresses. the addresses similarly have their own mappers, so code flow would be something like:
CustomerMapper->update;
update customer
foreach addresss
AddressMapper->update
I typically use postgres functions to do handle this, but what if I don't have the luxury of functions on postgres and have to do it inside the objects? I'm thinking something like a "CustomerWriter" class;
Is my line of thought here any good?PHP Code:class CustomerWriter
{
function save()
{
$db->query('BEGIN TRANSACTION');
$cm =& new CustomerMapper();
$result = $cm->save($this->customer);
if ($result)
$db->query('COMMIT');
}
}
Thanks for any help,
Richard




Bookmarks