Skip to content

Commit

Permalink
Merge branch 'DDC-2579' into 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Aug 10, 2013
2 parents 758955e + e250572 commit ec36e2c
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,8 @@ public function delete($entity)
$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'];
}
Expand All @@ -580,7 +580,7 @@ public function delete($entity)
}

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]);
Expand Down
180 changes: 180 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<?php

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;

/**
* @group DDC-2579
*/
class DDC2579Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
parent::setUp();

Type::addType(DDC2579Type::NAME, DDC2579Type::CLASSNAME);

$this->_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;
}
}

0 comments on commit ec36e2c

Please sign in to comment.