Break in 2.8: Cannot bind QueryBuilder parameters with \IteratorAggregate entities: leads to incorrect SQL generated code #6577

Closed
opened 2026-01-22 15:35:15 +01:00 by admin · 3 comments
Owner

Originally created by @ambroisemaupate on GitHub (Dec 4, 2020).

Bug Report

Binding QueryBuilder query parameters to entities that implements \IteratorAggregate leads to incorrect DQL generated code.

Q A
BC Break yes
Version 2.8.x-dev 418587b
Working on 2.7 branch

It seems that QueryBuilder tries to serialize object instead of using its primary key:

// Node is a valid Doctrine entity with primary key
// Node implements \IteratorAggregate, \Countable
$node = $this->_em->find(Node::class, $nodeId);

// …

$qb = $this->createQueryBuilder('t');
$qb->select('t')
    ->innerJoin('t.nodeSources', 'ns')
    ->andWhere($qb->expr()->eq('ns.node', ':node'))
    ->setParameter('node', $node);

leads into:

An exception occurred while executing […]
n1_.node_id = ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? 
with params [7, false, false, false, false, false, false, false, false, false, false, false, false]:

To fix this I need to explicitely use primary key $node->getId():

$qb = $this->createQueryBuilder('t');
$qb->select('t')
    ->innerJoin('t.nodeSources', 'ns')
    ->andWhere($qb->expr()->eq('ns.node', ':node'))
    ->setParameter('node', $node->getId());

https://github.com/doctrine/orm/issues/8181

Originally created by @ambroisemaupate on GitHub (Dec 4, 2020). ### Bug Report Binding QueryBuilder query parameters to entities that implements \IteratorAggregate leads to incorrect DQL generated code. Q | A -- | -- BC Break | yes Version | 2.8.x-dev `418587b` Working on | 2.7 branch It seems that QueryBuilder tries to serialize object instead of using its *primary key*: ```php // Node is a valid Doctrine entity with primary key // Node implements \IteratorAggregate, \Countable $node = $this->_em->find(Node::class, $nodeId); // … $qb = $this->createQueryBuilder('t'); $qb->select('t') ->innerJoin('t.nodeSources', 'ns') ->andWhere($qb->expr()->eq('ns.node', ':node')) ->setParameter('node', $node); ``` leads into: ``` An exception occurred while executing […] n1_.node_id = ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? with params [7, false, false, false, false, false, false, false, false, false, false, false, false]: ``` To fix this I need to explicitely use primary key `$node->getId()`: ```php $qb = $this->createQueryBuilder('t'); $qb->select('t') ->innerJoin('t.nodeSources', 'ns') ->andWhere($qb->expr()->eq('ns.node', ':node')) ->setParameter('node', $node->getId()); ``` https://github.com/doctrine/orm/issues/8181
admin closed this issue 2026-01-22 15:35:15 +01:00
Author
Owner

@ambroisemaupate commented on GitHub (Dec 4, 2020):

Possibly due to

https://github.com/doctrine/orm/blob/2.8.x/lib/Doctrine/ORM/AbstractQuery.php#L423

@ambroisemaupate commented on GitHub (Dec 4, 2020): Possibly due to https://github.com/doctrine/orm/blob/2.8.x/lib/Doctrine/ORM/AbstractQuery.php#L423
Author
Owner

@ambroisemaupate commented on GitHub (Dec 4, 2020):

Here is a test case to reproduce this issue:

eca3a3fb15

@ambroisemaupate commented on GitHub (Dec 4, 2020): Here is a test case to reproduce this issue: https://github.com/ambroisemaupate/orm/commit/eca3a3fb158e8d39de2b6db2d552d10c140544bd
Author
Owner

@beberlei commented on GitHub (Dec 4, 2020):

Fixed by #8371

@beberlei commented on GitHub (Dec 4, 2020): Fixed by #8371
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6577