From 1fbe1ffc5a5ddb00d074d7090c533a9758d3260e Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 29 Jul 2013 13:10:09 -0400 Subject: [PATCH] fix DDC-2579 --- .../ORM/Persisters/BasicEntityPersister.php | 4 +- .../ORM/Functional/Ticket/DDC2579Test.php | 180 ++++++++++++++++++ 2 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 66e949ca8..00b00cfa2 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -567,8 +567,8 @@ class BasicEntityPersister $tableName = $this->quoteStrategy->getTableName($class, $this->platform); $idColumns = $this->quoteStrategy->getIdentifierColumnNames($class, $this->platform); $id = array_combine($idColumns, $identifier); + $types = array_map(function ($identifier) use ($class, $em) { - $types = array_map(function ($identifier) use ($class, $em) { if (isset($class->fieldMappings[$identifier])) { return $class->fieldMappings[$identifier]['type']; } @@ -580,7 +580,7 @@ class BasicEntityPersister } if (isset($targetMapping->associationMappings[$targetMapping->identifier[0]])) { - $types[] = $targetMapping->associationMappings[$targetMapping->identifier[0]]['type']; + return $targetMapping->associationMappings[$targetMapping->identifier[0]]['type']; } throw ORMException::unrecognizedField($targetMapping->identifier[0]); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php new file mode 100644 index 000000000..fe68ff564 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php @@ -0,0 +1,180 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(DDC2579Entity::CLASSNAME), + $this->_em->getClassMetadata(DDC2579EntityAssoc::CLASSNAME), + $this->_em->getClassMetadata(DDC2579AssocAssoc::CLASSNAME), + )); + } + + public function testIssue() + { + $id = new DDC2579Id("foo"); + $assoc = new DDC2579AssocAssoc($id); + $assocAssoc = new DDC2579EntityAssoc($assoc); + $entity = new DDC2579Entity($assocAssoc); + $repository = $this->_em->getRepository(DDC2579Entity::CLASSNAME); + + $this->_em->persist($assoc); + $this->_em->persist($assocAssoc); + $this->_em->persist($entity); + $this->_em->flush(); + + $entity->value++; + + $this->_em->persist($entity); + $this->_em->flush(); + $this->_em->clear(); + + $id = $entity->id; + $value = $entity->value; + $criteria = array('assoc' => $assoc, 'id' => $id); + $entity = $repository->findOneBy($criteria); + + $this->assertInstanceOf(DDC2579Entity::CLASSNAME, $entity); + $this->assertEquals($value, $entity->value); + + $this->_em->remove($entity); + $this->_em->flush(); + $this->_em->clear(); + + $this->assertNull($repository->findOneBy($criteria)); + $this->assertCount(0, $repository->findAll()); + } +} + +/** + * @Entity + */ +class DDC2579Entity +{ + + const CLASSNAME = __CLASS__; + + /** + * @Id + * @Column(type="ddc2579") + */ + public $id; + + /** + * @Id + * @ManyToOne(targetEntity="DDC2579EntityAssoc") + * @JoinColumn(name="relation_id", referencedColumnName="association_id") + */ + public $assoc; + + /** + * @Column(type="integer") + */ + public $value; + + public function __construct(DDC2579EntityAssoc $assoc, $value = 0) + { + $this->id = $assoc->assocAssoc->associationId; + $this->assoc = $assoc; + $this->value = $value; + } + +} + +/** + * @Entity + */ +class DDC2579EntityAssoc +{ + const CLASSNAME = __CLASS__; + + /** + * @Id + * @ManyToOne(targetEntity="DDC2579AssocAssoc") + * @JoinColumn(name="association_id", referencedColumnName="associationId") + */ + public $assocAssoc; + + public function __construct(DDC2579AssocAssoc $assocAssoc) + { + $this->assocAssoc = $assocAssoc; + } +} + +/** + * @Entity + */ +class DDC2579AssocAssoc +{ + const CLASSNAME = __CLASS__; + + /** + * @Id + * @Column(type="ddc2579") + */ + public $associationId; + + public function __construct(DDC2579Id $id) + { + $this->associationId = $id; + } +} + + +class DDC2579Type extends StringType +{ + const NAME = 'ddc2579'; + const CLASSNAME = __CLASS__; + + /** + * {@inheritdoc} + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + return (string)$value; + } + + public function convertToPhpValue($value, AbstractPlatform $platform) + { + return new DDC2579Id($value); + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return self::NAME; + } +} + +class DDC2579Id +{ + const CLASSNAME = __CLASS__; + + private $val; + + public function __construct($val) + { + $this->val = $val; + } + + public function __toString() + { + return $this->val; + } +}