$em->flush($entity) flushes all entities scheduled for insert #5812

Closed
opened 2026-01-22 15:18:36 +01:00 by admin · 1 comment
Owner

Originally created by @jskarpe on GitHub (Dec 20, 2017).

Originally assigned to: @Ocramius on GitHub.

doctrine/orm: v2.5.12

I have an entity without any relations set that I pass to flush().

Expected result

INSERT of only this entity

Actual result

All entities scheduled for inserts are put into the database


Looking at the code, computing changesets for all insert changesets in computeSingleEntityChangeSet seems strange to me:

UnitOfWork.php -> function computeSingleEntityChangeSet contains the following:

// Compute changes for INSERTed entities first. This must always happen even in this case.
$this->computeScheduleInsertsChangeSets();

With computeScheduleInsertsChangeSets:

/**
 * Computes the changesets of all entities scheduled for insertion.
 *
 * @return void
 */
private function computeScheduleInsertsChangeSets()
{
    foreach ($this->entityInsertions as $entity) {
        $class = $this->em->getClassMetadata(get_class($entity));

        $this->computeChangeSet($class, $entity);
    }
}
Originally created by @jskarpe on GitHub (Dec 20, 2017). Originally assigned to: @Ocramius on GitHub. doctrine/orm: v2.5.12 I have an entity without any relations set that I pass to flush(). **Expected result** INSERT of only this entity **Actual result** All entities scheduled for inserts are put into the database --- Looking at the code, computing changesets for all insert changesets in `computeSingleEntityChangeSet` seems strange to me: UnitOfWork.php -> `function computeSingleEntityChangeSet` contains the following: // Compute changes for INSERTed entities first. This must always happen even in this case. $this->computeScheduleInsertsChangeSets(); With computeScheduleInsertsChangeSets: /** * Computes the changesets of all entities scheduled for insertion. * * @return void */ private function computeScheduleInsertsChangeSets() { foreach ($this->entityInsertions as $entity) { $class = $this->em->getClassMetadata(get_class($entity)); $this->computeChangeSet($class, $entity); } }
admin added the Won't FixQuestion labels 2026-01-22 15:18:36 +01:00
admin closed this issue 2026-01-22 15:18:36 +01:00
Author
Owner

@Ocramius commented on GitHub (Dec 20, 2017):

This is normal: EntityManager#flush($entity) is deprecated, as it was initially only thought for performance optimisations, but does indeed perform any DB operations that were already scheduled.

Please don't use it, and just use EntityManager#flush() instead.

@Ocramius commented on GitHub (Dec 20, 2017): This is normal: `EntityManager#flush($entity)` is deprecated, as it was initially only thought for performance optimisations, but does indeed perform any DB operations that were already scheduled. Please don't use it, and just use `EntityManager#flush()` instead.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5812