Jira issue originally created by user mridgway:
This bug was encountered using a DateTime type as an @Id, but it appears that it will affect any type of custom data type if it is an object.
Doctrine\ORM\Id\AssignedGenerator checks to see if the key is an object. If so it does a look up in the identity map to find the object, but in the case of DateTime it will not find it and throws an exception. It is appears this is the case for both singular and composite keys as shown in the attached test.
Offending code: https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Id/AssignedGenerator.php#L52
Test case forthcoming.
Comment created by mridgway:
Test case: https://github.com/mridgway/doctrine2/blob/[DDC-1209](http://www.doctrine-project.org/jira/browse/DDC-1209)/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php
I posted a fix and it was merged this morning by Guilherme: #74
Issue was closed with resolution "Fixed"
Comment created by jonathaningram:
I am wondering if this fix is working correctly or has regressed?
I have a YAML file as follows:
# It seems this is not working
So the "dateExecuted" field is used to compose an artificial primary key since the table has no PK.
The error is:
Catchable Fatal Error: Object of class DateTime could not be converted to string in vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1295
() at vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1295
Symfony\Component\HttpKernel\Debug\ErrorHandler->handle() at n/a:n/a
implode() at vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1295
Doctrine\ORM\UnitOfWork->addToIdentityMap() at vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1125
Doctrine\ORM\UnitOfWork->scheduleForInsert() at vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:810
Doctrine\ORM\UnitOfWork->persistNew() at vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1540
Doctrine\ORM\UnitOfWork->doPersist() at vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1501
Doctrine\ORM\UnitOfWork->persist() at vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:565
In my composer.json, the relevant versions of Doctrine are:
Is this a bug or am I misusing this?
Comment created by stof:
this has never been supported. Doctrine 2 has always required id fields to be castable as string, which is not the case of a DateTime object
But didn't the PR #74 get merged in 98bc3c4 ? And you can see the use of @Id in the test cases, e.g. 98bc3c4#L2R78 ?