Merge pull request #74 from mridgway/DDC-1209
[DDC-1209] Fixed custom object types as @Id
This commit is contained in:
commit
98bc3c4e40
@ -49,7 +49,7 @@ class AssignedGenerator extends AbstractIdGenerator
|
|||||||
foreach ($idFields as $idField) {
|
foreach ($idFields as $idField) {
|
||||||
$value = $class->reflFields[$idField]->getValue($entity);
|
$value = $class->reflFields[$idField]->getValue($entity);
|
||||||
if (isset($value)) {
|
if (isset($value)) {
|
||||||
if (is_object($value)) {
|
if (isset($class->associationMappings[$idField])) {
|
||||||
if (!$em->getUnitOfWork()->isInIdentityMap($value)) {
|
if (!$em->getUnitOfWork()->isInIdentityMap($value)) {
|
||||||
throw ORMException::entityMissingForeignAssignedId($entity, $value);
|
throw ORMException::entityMissingForeignAssignedId($entity, $value);
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ class AssignedGenerator extends AbstractIdGenerator
|
|||||||
$idField = $class->identifier[0];
|
$idField = $class->identifier[0];
|
||||||
$value = $class->reflFields[$idField]->getValue($entity);
|
$value = $class->reflFields[$idField]->getValue($entity);
|
||||||
if (isset($value)) {
|
if (isset($value)) {
|
||||||
if (is_object($value)) {
|
if (isset($class->associationMappings[$idField])) {
|
||||||
if (!$em->getUnitOfWork()->isInIdentityMap($value)) {
|
if (!$em->getUnitOfWork()->isInIdentityMap($value)) {
|
||||||
throw ORMException::entityMissingForeignAssignedId($entity, $value);
|
throw ORMException::entityMissingForeignAssignedId($entity, $value);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ class ORMException extends Exception
|
|||||||
public static function entityMissingForeignAssignedId($entity, $relatedEntity)
|
public static function entityMissingForeignAssignedId($entity, $relatedEntity)
|
||||||
{
|
{
|
||||||
return new self(
|
return new self(
|
||||||
"Entity of type " . get_class($entity) . " has identity through a foreign entity " . get_class($relatedEntityClass) . ", " .
|
"Entity of type " . get_class($entity) . " has identity through a foreign entity " . get_class($relatedEntity) . ", " .
|
||||||
"however this entity has no ientity itself. You have to call EntityManager#persist() on the related entity " .
|
"however this entity has no ientity itself. You have to call EntityManager#persist() on the related entity " .
|
||||||
"and make sure it an identifier was generated before trying to persist '" . get_class($entity) . "'. In case " .
|
"and make sure it an identifier was generated before trying to persist '" . get_class($entity) . "'. In case " .
|
||||||
"of Post Insert ID Generation (such as MySQL Auto-Increment or PostgreSQL SERIAL) this means you have to call " .
|
"of Post Insert ID Generation (such as MySQL Auto-Increment or PostgreSQL SERIAL) this means you have to call " .
|
||||||
|
125
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php
Normal file
125
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||||
|
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../../TestInit.php';
|
||||||
|
|
||||||
|
class DDC1209Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
|
{
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
try {
|
||||||
|
$this->_schemaTool->createSchema(array(
|
||||||
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_1'),
|
||||||
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_2'),
|
||||||
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_3')
|
||||||
|
));
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-1209
|
||||||
|
*/
|
||||||
|
public function testIdentifierCanHaveCustomType()
|
||||||
|
{
|
||||||
|
$this->_em->persist(new DDC1209_3());
|
||||||
|
$this->_em->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-1209
|
||||||
|
*/
|
||||||
|
public function testCompositeIdentifierCanHaveCustomType()
|
||||||
|
{
|
||||||
|
$future1 = new DDC1209_1();
|
||||||
|
$this->_em->persist($future1);
|
||||||
|
|
||||||
|
$this->_em->flush();
|
||||||
|
|
||||||
|
$future2 = new DDC1209_2($future1);
|
||||||
|
$this->_em->persist($future2);
|
||||||
|
|
||||||
|
$this->_em->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class DDC1209_1
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Id @GeneratedValue @Column(type="integer")
|
||||||
|
*/
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class DDC1209_2
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @ManyToOne(targetEntity="DDC1209_1")
|
||||||
|
* @JoinColumn(referencedColumnName="id", nullable=false)
|
||||||
|
*/
|
||||||
|
private $future1;
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(type="datetime", nullable=false)
|
||||||
|
*/
|
||||||
|
private $starting_datetime;
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(type="datetime", nullable=false)
|
||||||
|
*/
|
||||||
|
private $during_datetime;
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(type="datetime", nullable=false)
|
||||||
|
*/
|
||||||
|
private $ending_datetime;
|
||||||
|
|
||||||
|
public function __construct(DDC1209_1 $future1)
|
||||||
|
{
|
||||||
|
$this->future1 = $future1;
|
||||||
|
$this->starting_datetime = new DateTime2();
|
||||||
|
$this->during_datetime = new DateTime2();
|
||||||
|
$this->ending_datetime = new DateTime2();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class DDC1209_3
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(type="datetime")
|
||||||
|
*/
|
||||||
|
private $date;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->date = new DateTime2();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DateTime2 extends \DateTime
|
||||||
|
{
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return $this->format('Y');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user