[PR #869] [CLOSED] Detach (DateTime) objects in original object data #8831

Open
opened 2026-01-22 16:01:53 +01:00 by admin · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/doctrine/orm/pull/869
Author: @tomphp
Created: 12/4/2013
Status: Closed

Base: masterHead: fix/detach-datetime-objects


📝 Commits (2)

  • e758650 Detach objects in original object data
  • a057554 Detach objects in original object data for refreshes also

📊 Changes

3 files changed (+81 additions, -3 deletions)

View changed files

📝 lib/Doctrine/ORM/UnitOfWork.php (+20 -2)
📝 tests/Doctrine/Tests/Models/Generic/DateTimeModel.php (+1 -1)
📝 tests/Doctrine/Tests/ORM/UnitOfWorkTest.php (+60 -0)

📄 Description

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

// MyEntity.php

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

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

    // ...

    public function setCreated(\DateTime $created)
    {
        $this->created = $created;
    }

    public function getCreated()
    {
        return $this->created;
    }

    // ...
}
// 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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/doctrine/orm/pull/869 **Author:** [@tomphp](https://github.com/tomphp) **Created:** 12/4/2013 **Status:** ❌ Closed **Base:** `master` ← **Head:** `fix/detach-datetime-objects` --- ### 📝 Commits (2) - [`e758650`](https://github.com/doctrine/orm/commit/e7586501d00322e95896d7b88d78989b9699a95d) Detach objects in original object data - [`a057554`](https://github.com/doctrine/orm/commit/a0575546cba68d40c522fcc8347ba4e4f552cb58) Detach objects in original object data for refreshes also ### 📊 Changes **3 files changed** (+81 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `lib/Doctrine/ORM/UnitOfWork.php` (+20 -2) 📝 `tests/Doctrine/Tests/Models/Generic/DateTimeModel.php` (+1 -1) 📝 `tests/Doctrine/Tests/ORM/UnitOfWorkTest.php` (+60 -0) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
admin added the pull-request label 2026-01-22 16:01:53 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#8831