ZF-3709: Inconsistent behaviour in Zend_Db_Table and supporting classes
Description
I stumbled across this inconsistency while following some of the examples of the framework documentation about Zend_Db_Table relationships
Sample tables:
CREATE TABLE owners (
id int(10) unsigned NOT NULL auto_increment PRIMARY_KEY,
name varchar(64) NOT NULL,
);
CREATE TABLE cars (
id int(10) unsigned NOT NULL auto_increment PRIMARY_KEY,
model varchar(64) NOT NULL,
);
CREATE TABLE owner_car (
owner_id int(10) unsigned NOT NULL,
car_id int(10) unsigned NOT NULL,
mileage int(10) unsigned NOT NULL,
);
Then the referenceMap for owner_car:
protected $_referenceMap = array(
'Owner' => array(
'columns' => array('owner_id'),
'refTableClass' => 'owners',
'refColumns' => array('id'),
),
'Car' => array(
'columns' => array('car_id'),
'refTableClass' => 'cars',
'refColumns' => array('id'),
)
);
Then when you use the findManyToManyRowset() from a Zend_Db_Table_Row object:
$ownerTable = new owners();
$ownerRecord = $ownerTable->fetchRow('id = 1');
$manyToManyRecords = $ownerRecord->findManyToManyRowset('cars', 'owner_car');
The resulting rows in the rowset contain the following columns:
owner_id, car_id, mileage, id, model,
the readOnly value of the row object will be false and the tableClass will be set to cars any subsequent save() will fail with an exception since not all returned columns are present in the cars table.
A variety of solutions are possible depending on the intended use cases but it does need some attention
Comments
Posted by Michael Rehbein (tech13) on 2009-11-24T11:21:34.000+0000
Wouldn't
in place of
work, so that the join table's columns are ignored.
Posted by Ralph Schindler (ralph) on 2010-02-19T13:14:41.000+0000
Fixed in trunk 21100 and in release branch 1.10 in 21102