Index: documentation/manual/en/module_specs/Zend_Db_Table-Relationships.xml =================================================================== --- documentation/manual/en/module_specs/Zend_Db_Table-Relationships.xml (revision 24473) +++ documentation/manual/en/module_specs/Zend_Db_Table-Relationships.xml (working copy) @@ -175,11 +175,11 @@ 'refColumns' entry. - - It is optional to specify this element. If you don't specify the - refColumns, the columns reported as the primary key columns - of the parent table are used by default. - + + + As of 1.11.11, the refColumns element is no longer optional. If you do not specify this element an exception will be thrown. + + Index: library/Zend/Db/Table/Abstract.php =================================================================== --- library/Zend/Db/Table/Abstract.php (revision 24473) +++ library/Zend/Db/Table/Abstract.php (working copy) @@ -1195,12 +1195,16 @@ { $this->_setupMetadata(); $rowsAffected = 0; - foreach ($this->_getReferenceMapNormalized() as $map) { + foreach ($this->_getReferenceMapNormalized() as $name=>$map) { if ($map[self::REF_TABLE_CLASS] == $parentTableClassname && isset($map[self::ON_DELETE])) { switch ($map[self::ON_DELETE]) { case self::CASCADE: $where = array(); for ($i = 0; $i < count($map[self::COLUMNS]); ++$i) { + if ( !isset($map[self::REF_COLUMNS]) ) { + require_once 'Zend/Db/Table/Exception.php'; + throw new Zend_Db_Table_Exception("Reference map '{$name}' on table '{$this->_name}' must have key '".self::REF_COLUMNS."'"); + } $col = $this->_db->foldCase($map[self::COLUMNS][$i]); $refCol = $this->_db->foldCase($map[self::REF_COLUMNS][$i]); $type = $this->_metadata[$col]['DATA_TYPE']; Index: tests/Zend/Db/Table/TestCommon.php =================================================================== --- tests/Zend/Db/Table/TestCommon.php (revision 24473) +++ tests/Zend/Db/Table/TestCommon.php (working copy) @@ -1652,6 +1652,44 @@ $this->assertEquals(1, count($rowset)); } + /** + * @group ZF-3144 + */ + public function testCascadingOperationReferenceColumnFallsBackToPrimaryKeyWhenNotSpecified() + { + Zend_Db_Table::setDefaultAdapter($this->_db); + + $this->_util->createTable('ZF3144_products', array( + 'id' => 'tinyint(4) NOT NULL', + 'PRIMARY KEY' => 'id' + )); + + $this->_util->createTable('ZF3144_files', array( + 'id' => 'tinyint(4) NOT NULL', + 'productId' => 'tinyint(4) NOT NULL', + 'PRIMARY KEY' => 'id' + )); + + require_once dirname(__FILE__) . "/_files/My/ZF3144/Products.php"; + $tblProducts = new My_ZF3144_Products(); + $tblProducts->createRow(array('id'=>1))->save(); + $tblProducts->createRow(array('id'=>2))->save(); + + require_once dirname(__FILE__) . "/_files/My/ZF3144/Files.php"; + $tblFiles = new My_ZF3144_Files(); + $tblFiles->createRow(array('id'=>7, 'productId'=>2))->save(); + $tblFiles->createRow(array('id'=>8, 'productId'=>2))->save(); + + try { + $tblProducts->find(2)->current()->delete(); + $this->fail('Expected exception Zend_Db_Table_Exception'); + } catch ( Zend_Db_Table_Exception $ex ) { } + + $this->_util->dropTable('ZF3144_products'); + $this->_util->dropTable('ZF3144_files'); + + Zend_Db_Table::setDefaultAdapter(); + } Index: tests/Zend/Db/Table/_files/My/ZF3144/Files.php =================================================================== --- tests/Zend/Db/Table/_files/My/ZF3144/Files.php (revision 0) +++ tests/Zend/Db/Table/_files/My/ZF3144/Files.php (revision 0) @@ -0,0 +1,49 @@ + array( + 'columns' => 'productId', + 'refTableClass' => 'My_ZF3144_Products', + // 'refColumns purposely omitted + 'onDelete' => self::CASCADE, + ), + ); +} Property changes on: tests/Zend/Db/Table/_files/My/ZF3144/Files.php ___________________________________________________________________ Added: svn:keywords + Id Index: tests/Zend/Db/Table/_files/My/ZF3144/Products.php =================================================================== --- tests/Zend/Db/Table/_files/My/ZF3144/Products.php (revision 0) +++ tests/Zend/Db/Table/_files/My/ZF3144/Products.php (revision 0) @@ -0,0 +1,43 @@ +