V
V
Vitaly Sorokin2017-09-14 08:06:28
symfony
Vitaly Sorokin, 2017-09-14 08:06:28

Why does flush($some) flush all changes?

Hello, today I encountered the following behavior in symfony:

$remove = $this->getEm()->getRepository('MainBundle:Something')->findOneBy([],['id'=>'ASC']);
$this->getEm()->remove($remove);

$city = new City();
$city->setName(date('U'));
$this->getEm()->persist($city);
$this->getEm()->flush($city);

As a result, remove is removed, although only the change to the city entity is expected to be saved. Why is this happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
voronkovich, 2017-09-14
@SorokinWS

Vitaly Sorokin , Answers here:
https://github.com/doctrine/doctrine2/blob/master/...
https://github.com/doctrine/doctrine2/blob/master/...

/**
 * Only flushes the given entity according to a ruleset that keeps the UoW consistent.
 *
 * 1. All entities scheduled for insertion, (orphan) removals and changes in collections are processed as well!
 * 2. Read Only entities are skipped.
 * 3. Proxies are skipped.
 * 4. Only if entity is properly managed.
 *
 * @param object $entity
 *
 * @return void
 *
 * @throws \InvalidArgumentException
 */
private function computeSingleEntityChangeSet($entity)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question