diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 2ee3cf4fe..90ff8ffa9 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -633,7 +633,11 @@ class BasicEntityPersister // TRICKY: since the association is specular source and target are flipped foreach ($owningAssoc['targetToSourceKeyColumns'] as $sourceKeyColumn => $targetKeyColumn) { if (isset($sourceClass->fieldNames[$sourceKeyColumn])) { - $identifier[$targetKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity); + // unset the old value and set the new sql aliased value here. By definition + // unset($identifier[$targetKeyColumn] works here with how UnitOfWork::createEntity() calls this method. + $identifier[$this->_getSQLTableAlias($targetClass->name) . "." . $targetKeyColumn] = + $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity); + unset($identifier[$targetKeyColumn]); } else { throw MappingException::joinColumnMustPointToMappedField( $sourceClass->name, $sourceKeyColumn @@ -1214,7 +1218,7 @@ class BasicEntityPersister } else if ($assoc !== null && strpos($field, " ") === false && strpos($field, "(") === false) { // very careless developers could potentially open up this normally hidden api for userland attacks, // therefore checking for spaces and function calls which are not allowed. - + // found a join column condition, not really a "field" $conditionSql .= $field; } else { diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php index fff4c9b82..0144b0998 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php @@ -34,7 +34,7 @@ class ECommerceCustomer * only one customer at the time, while a customer can choose only one * mentor. Not properly appropriate but it works. * - * @OneToOne(targetEntity="ECommerceCustomer", cascade={"persist"}) + * @OneToOne(targetEntity="ECommerceCustomer", cascade={"persist"}, fetch="EAGER") * @JoinColumn(name="mentor_id", referencedColumnName="id") */ private $mentor; diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php index 321f66340..d7132ed60 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php @@ -49,6 +49,14 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction $this->assertForeignKeyIs(null); } + public function testFind() + { + $id = $this->_createFixture(); + + $customer = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceCustomer', $id); + $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $customer->getMentor()); + } + public function testEagerLoadsAssociation() { $this->_createFixture(); @@ -127,6 +135,8 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction $this->_em->flush(); $this->_em->clear(); + + return $customer->getId(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php new file mode 100644 index 000000000..3a756da9a --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php @@ -0,0 +1,96 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1250ClientHistory'), + )); + } catch(\PDOException $e) { + + } + } + + public function testIssue() + { + $c1 = new DDC1250ClientHistory; + $c2 = new DDC1250ClientHistory; + $c1->declinedClientsHistory = $c2; + $c1->declinedBy = $c2; + $c2->declinedBy = $c1; + $c2->declinedClientsHistory= $c1; + + $this->_em->persist($c1); + $this->_em->persist($c2); + $this->_em->flush(); + $this->_em->clear(); + + $history = $this->_em->createQuery('SELECT h FROM ' . __NAMESPACE__ . '\\DDC1250ClientHistory h WHERE h.id = ?1') + ->setParameter(1, $c2->id)->getSingleResult(); + + $this->assertInstanceOf(__NAMESPACE__ . '\\DDC1250ClientHistory', $history); + } +} + +/** + * @Entity + */ +class DDC1250ClientHistory +{ + /** @Id @GeneratedValue @Column(type="integer") */ + public $id; + + /** @OneToOne(targetEntity="DDC1250ClientHistory", inversedBy="declinedBy") + * @JoinColumn(name="declined_clients_history_id", referencedColumnName="id") + */ + public $declinedClientsHistory; + + /** + * @OneToOne(targetEntity="DDC1250ClientHistory", mappedBy="declinedClientsHistory") + * @var + */ + public $declinedBy; +} + +/** + * +Entities\ClientsHistory: +type: entity +table: clients_history +fields: +id: +id: true +type: integer +unsigned: false +nullable: false +generator: +strategy: IDENTITY +[...skiped...] +oneToOne: +declinedClientsHistory: +targetEntity: Entities\ClientsHistory +joinColumn: +name: declined_clients_history_id +referencedColumnName: id +inversedBy: declinedBy +declinedBy: +targetEntity: Entities\ClientsHistory +mappedBy: declinedClientsHistory +lifecycleCallbacks: { } +repositoryClass: Entities\ClientsHistoryRepository + + + */ \ No newline at end of file