Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jskarpe opened this issue Dec 20, 2017 · 1 comment
Closed

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

jskarpe opened this issue Dec 20, 2017 · 1 comment
Assignees

Comments

@jskarpe
Copy link

jskarpe commented Dec 20, 2017

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);
    }
}
@Ocramius
Copy link
Member

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 Ocramius self-assigned this Dec 20, 2017
@jskarpe jskarpe changed the title $em->flush($entity) flushes all entities schedules for insert $em->flush($entity) flushes all entities scheduled for insert Dec 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants