Open kira0269 opened 4 weeks ago
I found a "workaround" in order to make it work: I set the fetch mode to 'EAGER'. This way, the collection is always initialized and the comparison with the enum works.
In my case, it's still acceptable since I don't have too many records to load.
For anyone wanting to help on that, the support of enum values need to be added in ManyToManyPersister::loadCriteria
Bug Report
Summary
Working with enums in matching criteria for collections does not work correctly for bot lazy and eager loading.
Current behavior
When filtering collections with
$collection->matching($criteria)
, if the collection is not initialized, the values from the criteria object won't be converted to database types. So\BackedEnum
s are not replaced by their scalar value.How to reproduce
Keep the default doctrine configuration. Below the config from my symfony application:
// Case 1 : without initiliazed collection $banishedComments = $page->getBanishedComments(); // ☠️ This will throw an exception and display the message "Object of class App\CommentStatus could not be converted to string"
// Case 1 : with initiliazed collection $comments = $page->getComments();
// This loop will initialize the collection foreach ($comments as $comment) { echo $comment->getCommentStatus()->value . "\n"; }
$banishedComments = $page->getBanishedComments(); // 🆗 This works
Object of class App\CommentStatus could not be converted to string
at vendor/doctrine/dbal/src/Driver/PDO/Statement.php:48 at PDOStatement->bindValue(2, object(CommentStatus), 2) (vendor/doctrine/dbal/src/Driver/PDO/Statement.php:48) at Doctrine\DBAL\Driver\PDO\Statement->bindValue(2, object(CommentStatus), 2) (vendor/doctrine/dbal/src/Driver/Middleware/AbstractStatementMiddleware.php:35) at Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware->bindValue(2, object(CommentStatus), 2) (vendor/doctrine/dbal/src/Logging/Statement.php:84) at Doctrine\DBAL\Logging\Statement->bindValue(2, object(CommentStatus), 2) (vendor/doctrine/dbal/src/Driver/Middleware/AbstractStatementMiddleware.php:35) at Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware->bindValue(2, object(CommentStatus), 2) (vendor/symfony/doctrine-bridge/Middleware/Debug/DBAL3/Statement.php:54) at Symfony\Bridge\Doctrine\Middleware\Debug\DBAL3\Statement->bindValue(2, object(CommentStatus), 2) (vendor/doctrine/dbal/src/Connection.php:1809) at Doctrine\DBAL\Connection->bindParameters(object(Statement), array(1, object(CommentStatus)), array('integer', 'string')) (vendor/doctrine/dbal/src/Connection.php:1097) at Doctrine\DBAL\Connection->executeQuery('...') (vendor/doctrine/orm/src/Persisters/Collection/ManyToManyPersister.php:273) at Doctrine\ORM\Persisters\Collection\ManyToManyPersister->loadCriteria(object(PersistentCollection), object(Criteria)) (vendor/doctrine/orm/src/PersistentCollection.php:575) at Doctrine\ORM\PersistentCollection->matching(object(Criteria)) (src/Entity/Page.php:118) at App\Entity\Page->getBanishedComments() (vendor/symfony/property-access/PropertyAccessor.php:388) at Symfony\Component\PropertyAccess\PropertyAccessor->readProperty(array(object(Page)), 'banishedComments', false) (vendor/symfony/property-access/PropertyAccessor.php:99) at Symfony\Component\PropertyAccess\PropertyAccessor->getValue(object(Page), 'banishedComments') (vendor/easycorp/easyadmin-bundle/src/Field/Configurator/CommonPreConfigurator.php:50) at EasyCorp\Bundle\EasyAdminBundle\Field\Configurator\CommonPreConfigurator->configure(object(FieldDto), object(EntityDto), object(AdminContext)) (vendor/easycorp/easyadmin-bundle/src/Factory/FieldFactory.php:107) at EasyCorp\Bundle\EasyAdminBundle\Factory\FieldFactory->processFields(object(EntityDto), object(FieldCollection)) (vendor/easycorp/easyadmin-bundle/src/Factory/EntityFactory.php:43)