Zend_Db_Table is a Table Data Gateway . it
acts as a gateway to the database table. One instance processes all the rows in the table.
This means that you have one class for each table. Your Model_DbTable_Foo represents the Foo table in your database and only this table. It should not be inserted into other tables. This is what you would use a different table class for. The cleanest option is to add another layer on top of TDG, which knows how to handle inserts into multiple tables, for example.
class Model_Gateway_FooBar { protected $_tables; public function __construct(Zend_Db_Table_Abstract $foo, Zend_Db_Table_Abstract $bar) { $this->_tables['foo'] = $foo; $this->_tables['bar'] = $bar; } public function addFoo($data) { $this->_tables['foo']->insert($data['foo']);
However, this is an application, and you can decide not to worry and just create a new instance of another class in the Foo class and make an insert there, for example.
$otherTable = new Model_DbTable_Bar; $otherTable->insert($data);
Another option would be to put the logic in the controller, but I cannot recommend it, because it is not the responsibility of the controller and usually the controllers should be thin and the models should be thick .
In isolation, when you do multiple inserts, you can use transactions to make both inserts work as expected, for example.
$this->_tables['foo']->getAdapter()->beginTransaction();
and then commit() or rollback() depending on the result of the request.
Also note that with ZF1.9 you can also instantiate Zend_Db_Table without having to define a specific subclass first, for example.
$fooTable = new Zend_Db_Table('foo');
See the Zend_Db_Table chapter in the ZF Reference Guide .