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

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

Open
chapterjason opened this issue May 19, 2024 · 0 comments · May be fixed by #1857
Open

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

chapterjason opened this issue May 19, 2024 · 0 comments · May be fixed by #1857
Labels

Comments

@chapterjason
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants