Zend Framework

Inconsistent behaviour in Zend_Db_Table and supporting classes

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: N/A N/A
  • Resolution: Fixed
  • Affects Version/s: 1.5.1
  • Fix Version/s: 1.10.2
  • Component/s: Zend_Db_Table
  • Labels:
    None

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

Issue Links

Activity

Hide
Michael Rehbein added a comment -

Wouldn't

Zend/Db/Table/Row/Abstract.php line 1053
$select->from(array('i' => $interName), array(), $interSchema)
               ->joinInner(array('m' => $matchName), $joinCond, Zend_Db_Select::SQL_WILDCARD, $matchSchema)
               ->setIntegrityCheck(false);

in place of

Zend/Db/Table/Row/Abstract.php line 1053
$select->from(array('i' => $interName), Zend_Db_Select::SQL_WILDCARD, $interSchema)
               ->joinInner(array('m' => $matchName), $joinCond, Zend_Db_Select::SQL_WILDCARD, $matchSchema)
               ->setIntegrityCheck(false);

work, so that the join table's columns are ignored.

Show
Michael Rehbein added a comment - Wouldn't
Zend/Db/Table/Row/Abstract.php line 1053
$select->from(array('i' => $interName), array(), $interSchema)
               ->joinInner(array('m' => $matchName), $joinCond, Zend_Db_Select::SQL_WILDCARD, $matchSchema)
               ->setIntegrityCheck(false);
in place of
Zend/Db/Table/Row/Abstract.php line 1053
$select->from(array('i' => $interName), Zend_Db_Select::SQL_WILDCARD, $interSchema)
               ->joinInner(array('m' => $matchName), $joinCond, Zend_Db_Select::SQL_WILDCARD, $matchSchema)
               ->setIntegrityCheck(false);
work, so that the join table's columns are ignored.
Hide
Ralph Schindler added a comment -

Fixed in trunk 21100 and in release branch 1.10 in 21102

Show
Ralph Schindler added a comment - Fixed in trunk 21100 and in release branch 1.10 in 21102

People

Vote (1)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: