-1

How can we edit manually final SQL query before execution in Symfony / Doctrine?

I need to change value MANUALLY in SQL, i know i can edit it postPersist in entity, but i'm in a special case that this solution is not working in my schema .

A small idea :

public function preFlush/onFlush/PostFlush((PreFlushEventArgs/.../...)  $eventArgs) {
    $em = $eventArgs->getEntityManager();
    $uow = $em->getUnitOfWork();

    foreach ($uow->getScheduledEntityInsertions() as $entity) {

        if($entity instanceof MyEntity) {
              //Change my value directly in SQL query

        }

    }

}
yivi
  • 42,438
  • 18
  • 116
  • 138
Titeufggg
  • 21
  • 3
  • Are you trying to update a value within your *MyEntity* or is it another separate entity? – Bossman Feb 10 '22 at 13:35
  • 1
    Also... What query are you trying to make? Can you edit your post with what you're trying to achieve? – Bossman Feb 10 '22 at 13:47

1 Answers1

-1
public function getSubscribedEvents(): array
{
    return [
        Events::preUpdate  => 'preUpdate',
    ];
}

public function preUpdate(LifecycleEventArgs $args): void
{
    $object = $args->getObject();

    if ($object instanceof MyEntity) {
        $object->setSomething('something');

        $meta = $args->getObjectManager()->getClassMetadata(MyEntity::class);
        $om->getUnitOfWork()->recomputeSingleEntityChangeSet($meta, $object);
    }
}
Artem
  • 1,426
  • 12
  • 17