Author: ts Date: Mon Nov 26 20:16:17 2007 New Revision: 6818 Log: - Fixed issue #11405: Ambiguous column names when using ezcPersistentManyToManyRelation. Column names are now correctly prefixed with their corresponding table names.
Modified: trunk/PersistentObject/ChangeLog trunk/PersistentObject/src/persistent_session.php trunk/PersistentObject/tests/data/relation.dba trunk/PersistentObject/tests/data/relation.sql trunk/PersistentObject/tests/data/relation_test.php trunk/PersistentObject/tests/data/relationtestperson.php trunk/PersistentObject/tests/many_to_many_relation.php Modified: trunk/PersistentObject/ChangeLog ============================================================================== --- trunk/PersistentObject/ChangeLog [iso-8859-1] (original) +++ trunk/PersistentObject/ChangeLog [iso-8859-1] Mon Nov 26 20:16:17 2007 @@ -2,6 +2,9 @@ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - Documentation updates and fixes. +- Fixed issue #11405: Ambiguous column names when using + ezcPersistentManyToManyRelation. Column names are now correctly prefixed + with their corresponding table names. 1.3.1 - Monday 13 August 2007 Modified: trunk/PersistentObject/src/persistent_session.php ============================================================================== --- trunk/PersistentObject/src/persistent_session.php [iso-8859-1] (original) +++ trunk/PersistentObject/src/persistent_session.php [iso-8859-1] Mon Nov 26 20:16:17 2007 @@ -483,6 +483,7 @@ $query = $this->createRelationFindQuery( $object, $relatedClass ); // This method only needs to return 1 object $query->limit( 1 ); + $resArr = $this->find( $query, $relatedClass ); if ( sizeof( $resArr ) < 1 ) { @@ -1129,9 +1130,10 @@ public function generateAliasMap( ezcPersistentObjectDefinition $def ) { $table = array(); + $table[$def->idProperty->propertyName] = $this->database->quoteIdentifier( $def->table ) . '.' . $this->database->quoteIdentifier( $def->idProperty->columnName ); foreach ( $def->properties as $prop ) { - $table[$prop->propertyName] = $this->database->quoteIdentifier( $prop->columnName ); + $table[$prop->propertyName] = $this->database->quoteIdentifier( $def->table ) . '.' . $this->database->quoteIdentifier( $prop->columnName ); } $table[$def->class] = $def->table; return $table; @@ -1146,10 +1148,10 @@ public function getColumnsFromDefinition( ezcPersistentObjectDefinition $def ) { $columns = array(); - $columns[] = $this->database->quoteIdentifier( $def->idProperty->columnName ); + $columns[] = $this->database->quoteIdentifier( $def->table ) . '.' . $this->database->quoteIdentifier( $def->idProperty->columnName ); foreach ( $def->properties as $property ) { - $columns[] = $this->database->quoteIdentifier( $property->columnName ); + $columns[] = $this->database->quoteIdentifier( $def->table ) . '.' . $this->database->quoteIdentifier( $property->columnName ); } return $columns; } Modified: trunk/PersistentObject/tests/data/relation.dba ============================================================================== --- trunk/PersistentObject/tests/data/relation.dba [iso-8859-1] (original) +++ trunk/PersistentObject/tests/data/relation.dba [iso-8859-1] Mon Nov 26 20:16:17 2007 @@ -146,6 +146,49 @@ )), ), )), + 'PO_friends' => + ezcDbSchemaTable::__set_state(array( + 'fields' => + array ( + 'friend_id' => + ezcDbSchemaField::__set_state(array( + 'type' => 'integer', + 'length' => 0, + 'notNull' => true, + 'default' => NULL, + 'autoIncrement' => false, + 'unsigned' => false, + )), + 'id' => + ezcDbSchemaField::__set_state(array( + 'type' => 'integer', + 'length' => 0, + 'notNull' => true, + 'default' => NULL, + 'autoIncrement' => false, + 'unsigned' => false, + )), + ), + 'indexes' => + array ( + 'primary' => + ezcDbSchemaIndex::__set_state(array( + 'indexFields' => + array ( + 'friend_id' => + ezcDbSchemaIndexField::__set_state(array( + 'sorting' => NULL, + )), + 'id' => + ezcDbSchemaIndexField::__set_state(array( + 'sorting' => NULL, + )), + ), + 'primary' => true, + 'unique' => true, + )), + ), + )), 'PO_persons' => ezcDbSchemaTable::__set_state(array( 'fields' => Modified: trunk/PersistentObject/tests/data/relation.sql ============================================================================== --- trunk/PersistentObject/tests/data/relation.sql [iso-8859-1] (original) +++ trunk/PersistentObject/tests/data/relation.sql [iso-8859-1] Mon Nov 26 20:16:17 2007 @@ -1,119 +1,104 @@ -- phpMyAdmin SQL Dump --- version 2.6.3-rc1 +-- version 2.11.2 -- http://www.phpmyadmin.net --- +-- -- Host: localhost --- Generation Time: Oct 16, 2006 at 07:10 PM --- Server version: 5.0.24 --- PHP Version: 5.1.6-pl6-gentoo --- +-- Generation Time: Nov 26, 2007 at 08:12 PM +-- Server version: 5.0.44 +-- PHP Version: 5.2.5RC2-dev + +SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; + +-- -- Database: `test` --- +-- -- -------------------------------------------------------- --- +-- -- Table structure for table `PO_addresses` --- +-- -CREATE TABLE `PO_addresses` ( - `id` tinyint(3) unsigned NOT NULL auto_increment, +CREATE TABLE IF NOT EXISTS `PO_addresses` ( + `city` varchar(100) NOT NULL, + `id` bigint(20) NOT NULL auto_increment, `street` varchar(100) NOT NULL, + `type` varchar(10) NOT NULL, `zip` varchar(5) NOT NULL, - `city` varchar(100) NOT NULL, - `type` varchar(10) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ; - --- --- Dumping data for table `PO_addresses` --- - -INSERT INTO `PO_addresses` (`id`, `street`, `zip`, `city`, `type`) VALUES (1, 'Httproad 23', '12345', 'Internettown', 'work'); -INSERT INTO `PO_addresses` (`id`, `street`, `zip`, `city`, `type`) VALUES (2, 'Ftpstreet 42', '12345', 'Internettown', 'work'); -INSERT INTO `PO_addresses` (`id`, `street`, `zip`, `city`, `type`) VALUES (3, 'Phpavenue 21', '12345', 'Internettown', 'private'); -INSERT INTO `PO_addresses` (`id`, `street`, `zip`, `city`, `type`) VALUES (4, 'Pythonstreet 13', '12345', 'Internettown', 'private'); +) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -------------------------------------------------------- --- +-- -- Table structure for table `PO_birthdays` --- +-- -CREATE TABLE `PO_birthdays` ( - `person_id` tinyint(4) NOT NULL, - `birthday` int(11) NOT NULL, +CREATE TABLE IF NOT EXISTS `PO_birthdays` ( + `birthday` bigint(20) NOT NULL, + `person_id` bigint(20) NOT NULL, PRIMARY KEY (`person_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- --- Dumping data for table `PO_birthdays` --- +-- -------------------------------------------------------- -INSERT INTO `PO_birthdays` (`person_id`, `birthday`) VALUES (1, 327535201); -INSERT INTO `PO_birthdays` (`person_id`, `birthday`) VALUES (2, -138243599); +-- +-- Table structure for table `PO_employers` +-- + +CREATE TABLE IF NOT EXISTS `PO_employers` ( + `id` bigint(20) NOT NULL auto_increment, + `name` varchar(100) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -------------------------------------------------------- --- --- Table structure for table `PO_employers` --- +-- +-- Table structure for table `PO_friends` +-- -CREATE TABLE `PO_employers` ( - `id` tinyint(4) NOT NULL auto_increment, - `name` varchar(100) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ; - --- --- Dumping data for table `PO_employers` --- - -INSERT INTO `PO_employers` (`id`, `name`) VALUES (1, 'Great Web 2.0 company'); -INSERT INTO `PO_employers` (`id`, `name`) VALUES (2, 'Oldschool Web 1.x company'); -INSERT INTO `PO_employers` (`id`, `name`) VALUES (3, 'Very oldschool print media company'); +CREATE TABLE IF NOT EXISTS `PO_friends` ( + `firiend_id` bigint(20) NOT NULL, + `id` bigint(20) NOT NULL, + PRIMARY KEY (`firiend_id`,`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -------------------------------------------------------- --- +-- -- Table structure for table `PO_persons` --- +-- -CREATE TABLE `PO_persons` ( - `id` tinyint(4) NOT NULL auto_increment, +CREATE TABLE IF NOT EXISTS `PO_persons` ( + `employer` bigint(20) default NULL, `firstname` varchar(100) NOT NULL, + `id` bigint(20) NOT NULL auto_increment, `surname` varchar(100) NOT NULL, - `employer` tinyint(4) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ; - --- --- Dumping data for table `PO_persons` --- - -INSERT INTO `PO_persons` (`id`, `firstname`, `surname`, `employer`) VALUES (1, 'Derick', 'Gopher', 2); -INSERT INTO `PO_persons` (`id`, `firstname`, `surname`, `employer`) VALUES (2, 'Frederick', 'Ajax', 1); -INSERT INTO `PO_persons` (`id`, `firstname`, `surname`, `employer`) VALUES (3, 'Raymond', 'Socialweb', 1); +) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -------------------------------------------------------- --- +-- -- Table structure for table `PO_persons_addresses` --- +-- -CREATE TABLE `PO_persons_addresses` ( - `person_id` tinyint(4) NOT NULL, - `address_id` tinyint(4) NOT NULL, - PRIMARY KEY (`person_id`,`address_id`) +CREATE TABLE IF NOT EXISTS `PO_persons_addresses` ( + `address_id` bigint(20) NOT NULL, + `person_id` bigint(20) NOT NULL, + PRIMARY KEY (`address_id`,`person_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- --- Dumping data for table `PO_persons_addresses` --- +-- -------------------------------------------------------- -INSERT INTO `PO_persons_addresses` (`person_id`, `address_id`) VALUES (1, 1); -INSERT INTO `PO_persons_addresses` (`person_id`, `address_id`) VALUES (1, 2); -INSERT INTO `PO_persons_addresses` (`person_id`, `address_id`) VALUES (1, 4); -INSERT INTO `PO_persons_addresses` (`person_id`, `address_id`) VALUES (2, 1); -INSERT INTO `PO_persons_addresses` (`person_id`, `address_id`) VALUES (2, 3); -INSERT INTO `PO_persons_addresses` (`person_id`, `address_id`) VALUES (2, 4); +-- +-- Table structure for table `PO_secondpersons_addresses` +-- + +CREATE TABLE IF NOT EXISTS `PO_secondpersons_addresses` ( + `address_id` bigint(20) NOT NULL, + `person_firstname` varchar(100) NOT NULL, + `person_surname` varchar(100) NOT NULL, + PRIMARY KEY (`address_id`,`person_firstname`,`person_surname`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; Modified: trunk/PersistentObject/tests/data/relation_test.php ============================================================================== --- trunk/PersistentObject/tests/data/relation_test.php [iso-8859-1] (original) +++ trunk/PersistentObject/tests/data/relation_test.php [iso-8859-1] Mon Nov 26 20:16:17 2007 @@ -33,6 +33,10 @@ $db->exec( "INSERT INTO " . $db->quoteIdentifier( "PO_birthdays" ) . " (" . $db->quoteIdentifier( "person_id" ) . ", " . $db->quoteIdentifier( "birthday" ) . ") VALUES (1, 327535201)" ); $db->exec( "INSERT INTO " . $db->quoteIdentifier( "PO_birthdays" ) . " (" . $db->quoteIdentifier( "person_id" ) . ", " . $db->quoteIdentifier( "birthday" ) . ") VALUES (2, -138243599)" ); + + $db->exec( "INSERT INTO " . $db->quoteIdentifier( "PO_friends" ) . " (" . $db->quoteIdentifier( "id" ) . ", " . $db->quoteIdentifier( "friend_id" ) . ") VALUES (1, 2)" ); + $db->exec( "INSERT INTO " . $db->quoteIdentifier( "PO_friends" ) . " (" . $db->quoteIdentifier( "id" ) . ", " . $db->quoteIdentifier( "friend_id" ) . ") VALUES (1, 3)" ); + $db->exec( "INSERT INTO " . $db->quoteIdentifier( "PO_friends" ) . " (" . $db->quoteIdentifier( "id" ) . ", " . $db->quoteIdentifier( "friend_id" ) . ") VALUES (2, 1)" ); } /** @@ -67,6 +71,7 @@ $db->exec( "DROP TABLE " . $db->quoteIdentifier( "PO_persons" ) ); $db->exec( "DROP TABLE " . $db->quoteIdentifier( "PO_persons_addresses" ) ); $db->exec( "DROP TABLE " . $db->quoteIdentifier( "PO_secondpersons_addresses" ) ); + $db->exec( "DROP TABLE " . $db->quoteIdentifier( "PO_friends" ) ); if ( $db->getName() === "oracle" ) { $db->exec( "DROP SEQUENCE " . $db->quoteIdentifier( "PO_addresses_id_seq" ) ); Modified: trunk/PersistentObject/tests/data/relationtestperson.php ============================================================================== --- trunk/PersistentObject/tests/data/relationtestperson.php [iso-8859-1] (original) +++ trunk/PersistentObject/tests/data/relationtestperson.php [iso-8859-1] Mon Nov 26 20:16:17 2007 @@ -42,6 +42,11 @@ new ezcPersistentDoubleTableMap( "id", "person_id", "address_id", "id" ), ); +$def->relations["RelationTestPerson"] = new ezcPersistentManyToManyRelation( "PO_persons", "PO_persons", "PO_friends" ); +$def->relations["RelationTestPerson"]->columnMap = array( + new ezcPersistentDoubleTableMap( "id", "id", "friend_id", "id" ), +); + return $def; ?> Modified: trunk/PersistentObject/tests/many_to_many_relation.php ============================================================================== --- trunk/PersistentObject/tests/many_to_many_relation.php [iso-8859-1] (original) +++ trunk/PersistentObject/tests/many_to_many_relation.php [iso-8859-1] Mon Nov 26 20:16:17 2007 @@ -512,6 +512,183 @@ "Address relation records not deleted correctly on Person delete." ); } + + public function testGetRelatedObjectWithAmbigiousColumn() + { + $person = $this->session->load( "RelationTestPerson", 1 ); + $res = RelationTestAddress::__set_state(array( + 'id' => '1', + 'street' => 'Httproad 23', + 'zip' => '12345', + 'city' => 'Internettown', + 'type' => 'work', + )); + + $this->assertEquals( + $res, + $this->session->getRelatedObject( $person, "RelationTestAddress" ), + "Related RelationTestPerson objects not fetched correctly." + ); + + $friends = $this->session->getRelatedObjects( $person, 'RelationTestPerson' ); + $res = array ( + 0 => + RelationTestPerson::__set_state(array( + 'id' => '2', + 'firstname' => 'Frederick', + 'surname' => 'Ajax', + 'employer' => '1', + )), + 1 => + RelationTestPerson::__set_state(array( + 'id' => '3', + 'firstname' => 'Raymond', + 'surname' => 'Socialweb', + 'employer' => '1', + )), + ); + + $this->assertEquals( + $res, + $friends + ); + } + + public function testRemoveRelatedObjectWithAmbigiousColumn() + { + $person = $this->session->load( "RelationTestPerson", 1 ); + $res = RelationTestAddress::__set_state(array( + 'id' => '1', + 'street' => 'Httproad 23', + 'zip' => '12345', + 'city' => 'Internettown', + 'type' => 'work', + )); + + $this->assertEquals( + $res, + $this->session->getRelatedObject( $person, "RelationTestAddress" ), + "Related RelationTestPerson objects not fetched correctly." + ); + + $friends = $this->session->getRelatedObjects( $person, 'RelationTestPerson' ); + $res = array ( + 0 => + RelationTestPerson::__set_state(array( + 'id' => '2', + 'firstname' => 'Frederick', + 'surname' => 'Ajax', + 'employer' => '1', + )), + 1 => + RelationTestPerson::__set_state(array( + 'id' => '3', + 'firstname' => 'Raymond', + 'surname' => 'Socialweb', + 'employer' => '1', + )), + ); + + $this->assertEquals( + $res, + $friends + ); + + $this->session->removeRelatedObject( $person, $friends[0] ); + + $friends = $this->session->getRelatedObjects( $person, 'RelationTestPerson' ); + $res = array ( + 0 => + RelationTestPerson::__set_state(array( + 'id' => '3', + 'firstname' => 'Raymond', + 'surname' => 'Socialweb', + 'employer' => '1', + )), + ); + + $this->assertEquals( + $res, + $friends + ); + } + + public function testAddRelatedObjectWithAmbigiousColumn() + { + $person = $this->session->load( "RelationTestPerson", 3 ); + $friends = $this->session->getRelatedObjects( $person, 'RelationTestPerson' ); + + $this->assertEquals( + array(), + $friends + ); + + $otherPerson = $this->session->load( "RelationTestPerson", 1 ); + + $this->session->addRelatedObject( $person, $otherPerson ); + + $friends = $this->session->getRelatedObjects( $person, 'RelationTestPerson' ); + $res = array ( + 0 => + RelationTestPerson::__set_state(array( + 'id' => '3', + 'firstname' => 'Raymond', + 'surname' => 'Socialweb', + 'employer' => '1', + )), + ); + } + + public function testDeleteRelatedObjectWithAmbigiousColumn() + { + $person = $this->session->load( "RelationTestPerson", 1 ); + $res = RelationTestAddress::__set_state(array( + 'id' => '1', + 'street' => 'Httproad 23', + 'zip' => '12345', + 'city' => 'Internettown', + 'type' => 'work', + )); + + $this->assertEquals( + $res, + $this->session->getRelatedObject( $person, "RelationTestAddress" ), + "Related RelationTestPerson objects not fetched correctly." + ); + + $friends = $this->session->getRelatedObjects( $person, 'RelationTestPerson' ); + $res = array ( + 0 => + RelationTestPerson::__set_state(array( + 'id' => '2', + 'firstname' => 'Frederick', + 'surname' => 'Ajax', + 'employer' => '1', + )), + 1 => + RelationTestPerson::__set_state(array( + 'id' => '3', + 'firstname' => 'Raymond', + 'surname' => 'Socialweb', + 'employer' => '1', + )), + ); + + $this->assertEquals( + $res, + $friends + ); + + $this->session->removeRelatedObject( $person, $friends[0] ); + $this->session->removeRelatedObject( $person, $friends[1] ); + + $friends = $this->session->getRelatedObjects( $person, 'RelationTestPerson' ); + + $this->assertEquals( + array(), + $this->session->getRelatedObjects( $person, 'RelationTestPerson' ) + ); + } } ?> -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components