In my event I check if start date is changed if is, then I want to insert new row, and cancel update
if ($args->hasChangedField('startAt')) {
// cancel update
// insert new entity
}
I have did something like this
public function preFlush(PreFlushEventArgs $args)
{
$em = $args->getEntityManager();
/** @var UnitOfWork $unitOfWork */
$unitOfWork = $em->getUnitOfWork();
$identityMap = $unitOfWork->getIdentityMap();
if (0 === count($identityMap)) {
return;
}
foreach ($identityMap as $entities) {
foreach ($entities as $entity) {
if ($entity instanceof Settelment) {
$original = $unitOfWork->getOriginalEntityData($entity);
if ($entity->getStartAt() !== $original['startAt']) {
$em->detach($entity); // remove entity
}
}
}
}
}
But now I remove entity and its ok but I dont define here new object and persist it, and I got extra row in database (this is what I want) but how does it work ?? why i get extra row if I didnt create entity.