>
> Do you have any sample code? I am not sure the best way to do this. When I
> instantiate a row from a child table like validating_user, I would like
> the corresponding row in validating to be available as if it were one
> combined table.
>
Hi Greg, sorry, I saw your email (off-list) but I didn't get to it yet.
I'll do it here so it gets archived.
Here's an example of what I had in mind in my earlier suggestion:
// table classes for use by the domain model
class validating extends Zend_Db_Table_Abstract { }
class validating_email extends Zend_Db_Table_Abstract { }
// domain model extends no base class
class UserModel
{
protected function generate_key($email)
{
return md5($email);
}
public function requestEmail($uid, $emailAddress)
{
$key = $this->generate_key($emailAddress);
$valTable = new validating();
$valRow = $valTable->createRow();
$valRow->key = $key;
$valRow->user_id = (int) $uid;
$valRow->creation_date = new Zend_Db_Expr('CURRENT_DATE()');
$valEmailTable = new validating_email();
$valEmailRow = $valEmailTable->createRow();
$valEmailRow->key = $key;
$valEmailRow->email = $emailAddress;
try {
$valTable->getAdapter()->beginTransaction();
$valRow->save();
$valEmailRow->save();
$valTable->getAdapter()->commit();
} catch (Zend_Db_Exception $e) {
$valTable->getAdapter()->rollback();
// log error, recover, whatever
}
}
}
$user = new UserModel();
$user->requestEmail(1234, 'user@example.org');
Regards,
Bill Karwin
--
View this message in context: http://www.nabble.com/Table-Inheritance--tp17716295p18841689.html
Sent from the Zend DB mailing list archive at Nabble.com.
没有评论:
发表评论