[DDC-2839] [GH-869] Detach objects in original object data Created: 04/Dec/13  Updated: 18/Aug/14  Resolved: 18/Aug/14

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Marco Pivetta
Resolution: Invalid Votes: 0
Labels: None


 Description   

This issue is created automatically through a Github pull request on behalf of tomphp:

Url: https://github.com/doctrine/doctrine2/pull/869

Message:

The PR makes Doctrine ORM update the database when you execute something like this:

```php
// MyEntity.php

/**

  • @Entity
    */
    class MyEntity
    {
    // ...

/**

  • @Column(type="datetime")
    */
    private $created;

// ...

public function setCreated(\DateTime $created)

{ $this->created = $created; }

public function getCreated()

{ return $this->created; }

// ...
}
```

```php
// Current problem

$entity = $entityManager->find('MyEntity', 1);

$entity->getCreated()->setDate('2001-01-01');

$entityManager->persist($entity);

$entityManager->flush();

// At this point no changes have been made to the database!
```

The reason this doesn't work currently is because the array of original data stored in the UnitOfWork contains the actual DateTime object which is in the entity. When you update the object in the entity the original data is updated also so the entity are the original value are still equal and therefore the object is not seen as changed.

I have chosen to clone all objects rather than just DateTime object include more types are included in the future.



 Comments   
Comment by Doctrine Bot [ 05/Dec/13 ]

A related Github Pull-Request [GH-869] was closed:
https://github.com/doctrine/doctrine2/pull/869

Generated at Wed Oct 01 22:54:24 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.