symfony / ux

Symfony UX initiative: a JavaScript ecosystem for Symfony

Home Page:https://ux.symfony.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Turbo] Doesn't work with entity that uses composite primary key

chapterjason opened this issue · comments

I noticed it is not possible to use an entity with a composite primary key for broadcasting.

It looks like instead of the id array which must be Stringable, the whole entity is returned and $id is something like [instanceof ClassA, instanceof ClassB]:

$id = $em->getClassMetadata($class)->getIdentifierValues($entity);
foreach ($options as $k => $option) {
$options[$k]['id'] = $id;
}

This will result in the appended exception here:

'id' => implode('-', (array) ($options['id'] ?? [])),

In TwigBroadcaster.php line 66:
                                                                     
  [Error]                                                            
  Object of class App\Entity\ClassA could not be converted to string  
                                                                     

Exception trace:
  at /[...]/project-name/vendor/symfony/ux-turbo/src/Broadcaster/TwigBroadcaster.php:66
 implode() at /[...]/project-name/vendor/symfony/ux-turbo/src/Broadcaster/TwigBroadcaster.php:66
 Symfony\UX\Turbo\Broadcaster\TwigBroadcaster->broadcast() at /[...]/project-name/vendor/symfony/ux-turbo/src/Doctrine/BroadcastListener.php:106
 Symfony\UX\Turbo\Doctrine\BroadcastListener->postFlush() at /[...]/project-name/vendor/symfony/doctrine-bridge/ContainerAwareEventManager.php:63
 Symfony\Bridge\Doctrine\ContainerAwareEventManager->dispatchEvent() at /[...]/project-name/vendor/doctrine/orm/src/UnitOfWork.php:3133
 Doctrine\ORM\UnitOfWork->dispatchPostFlushEvent() at /[...]/project-name/vendor/doctrine/orm/src/UnitOfWork.php:465
 Doctrine\ORM\UnitOfWork->commit() at /[...]/project-name/vendor/doctrine/orm/src/EntityManager.php:259
 Doctrine\ORM\EntityManager->flush() at /[...]/project-name/src/EventListener/ClassAEventListener.php:137
 
 // Unrelated console -> event dispatcher chain
 App\EventListener\ClassAEventListener->onClassAChanged() at /[...]/project-name/vendor/symfony/event-dispatcher/Debug/WrappedListener.php:116
 Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke() at /[...]/project-name/vendor/symfony/event-dispatcher/EventDispatcher.php:206
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /[...]/project-name/vendor/symfony/console/Application.php:318
 Symfony\Component\Console\Application->doRun() at /[...]/project-name/vendor/symfony/framework-bundle/Console/Application.php:79
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /[...]/project-name/vendor/symfony/console/Application.php:169
 Symfony\Component\Console\Application->run() at /[...]/project-name/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49
 Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() at /[...]/project-name/vendor/autoload_runtime.php:29
 require_once() at /[...]/project-name/bin/console:15