Update lib/Doctrine/ORM/UnitOfWork.php#550
Update lib/Doctrine/ORM/UnitOfWork.php#550cedriclombardot wants to merge 1 commit intodoctrine:masterfrom
Conversation
When the pk contains a DateTime object doctrine fail to create the index, because implode call __toString wich doesn't exists in \DateTime object
|
Hello, thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link: |
|
@cedriclombardot: if the problem is comparing same datetimes, do following in your entities instead: public function getDate()
{
return clone $this->date;
}
public function setDate(DateTime $date)
{
$this->date = clone $date;
}This will ensure your instance is always different. This patch is invalid. |
|
Its not about comparing same dates, it's only because at this line do https://github.com/cedriclombardot/doctrine2/blob/b4dc6080b3dd95d2ba23b3abe8cff70668acafcf/lib/Doctrine/ORM/UnitOfWork.php#L2464 an My composite PK is base on an integer column and on a datetime column and doctrine for datetime column use |
|
@cedriclombardot what about using an extended version of |
|
And how you can override all instance of \DateTime to enable a __toString ? |
|
@cedriclombardot: custom type and setters/getters that handle the conversion |
|
@cedriclombardot you can implement a Doctrine\DBAL\Types\Type subtype and derive from the DateTime type, which has the date time with __toString. Its a bit to work on, but we haven't found the perfect internal solution yet to take this work from our users. |
|
@beberlei I'm using simple derived entity: http://docs.doctrine-project.org/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity And i have the same problem, i have one entity Publisher another Account. Publisher: * @var integer
*
* @ORM\Id
* @ORM\OneToOne(targetEntity="EB\Core\KernelBundle\Entity\Account\Account")
* @ORM\JoinColumn(name="id", referencedColumnName="id", nullable=false)
*/
protected $id;And I have exactly the same problem as described by @cedriclombardot I can solve it, implementing __toString() in account, but doesn't sounds good, is what i need to do? In that case why is not documented? |
|
@eb-eoliveira you need the You can get a longer explanation at http://stackoverflow.com/questions/15080573/doctrine-2-orm-datetime-field-in-identifier, which is the problem described by @cedriclombardot |
|
@Ocramius thanks for the explanation, I suggest that at documentation (http://docs.doctrine-project.org/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity) should be added a note about it. |
|
@eb-eoliveira it should work for composite primary keys, can you paste your error message and the full stack trace into a gist or pastebin? |
|
@eb-eoliveira sorry, gave you misleading information. As @beberlei said, this should work |
|
Account Publisher: https://gist.github.com/eb-eoliveira/5413730 Account Entity: https://gist.github.com/eb-eoliveira/5413718 Stack trace: https://gist.github.com/eb-eoliveira/5413761 On stack trace you can see that the last line of code before enter doctrine code is: You can check it: https://gist.github.com/eb-eoliveira/5413804 $res = $this->getEntityManager()->merge($cacheRes);All works wonderful if I add a __toString() to Account entity. I'm doing something wrong? |
|
what version of ORM are you using? |
|
2.4.0-BETA1 More info: I'm using the beta, because I got problems on serialize and unserialize (http://www.doctrine-project.org/jira/browse/DDC-2306) so I updated to 2.4 beta to solve the problem. Let me know if you need more info. |
When the pk contains a DateTime object doctrine fail to create the index, because implode call __toString wich doesn't exists in \DateTime object