COUNT entities with OneToOne as identifier does not work since 2.5 #5224

Open
opened 2026-01-22 15:01:57 +01:00 by admin · 5 comments
Owner

Originally created by @olexp on GitHub (Aug 18, 2016).

Originally assigned to: @guilhermeblanco on GitHub.

I have an entity with Id as OneToOne to another entity.

class MailList
{

    /**
     * @ORM\Id
     * @ORM\OneToOne(targetEntity="Product")
     * @ORM\JoinColumn(referencedColumnName="product_id")
     */
    private $product;

ZfcDatagrid uses query builder as data source and creates following query to check if data is available:

SELECT COUNT(m) FROM Setup\Entity\MailList m INNER JOIN m.product p

Starting from 2.5.0 query returns an error:

>vendor\bin\doctrine-module.bat orm:run-dql "SELECT COUNT(m) FROM Setup\Entity\MailList m INNER JOIN m.product p"

  [Doctrine\ORM\Query\QueryException]
  [Semantical Error] line 0, col 13 near 'm) FROM Setup\Entity\MailList': Err
  or: Invalid PathExpression. Must be a StateFieldPathExpression.

The last version where this query is working is 2.4.8.
Please help to find out what is wrong.

Originally created by @olexp on GitHub (Aug 18, 2016). Originally assigned to: @guilhermeblanco on GitHub. I have an entity with Id as OneToOne to another entity. ``` class MailList { /** * @ORM\Id * @ORM\OneToOne(targetEntity="Product") * @ORM\JoinColumn(referencedColumnName="product_id") */ private $product; ``` [ZfcDatagrid](https://github.com/ThaDafinser/ZfcDatagrid) uses query builder as data source and creates following query to check if data is available: SELECT COUNT(m) FROM Setup\Entity\MailList m INNER JOIN m.product p Starting from 2.5.0 query returns an error: ``` >vendor\bin\doctrine-module.bat orm:run-dql "SELECT COUNT(m) FROM Setup\Entity\MailList m INNER JOIN m.product p" [Doctrine\ORM\Query\QueryException] [Semantical Error] line 0, col 13 near 'm) FROM Setup\Entity\MailList': Err or: Invalid PathExpression. Must be a StateFieldPathExpression. ``` The last version where this query is working is 2.4.8. Please help to find out what is wrong.
Author
Owner

@JCMais commented on GitHub (Aug 18, 2016):

Can you try SELECT COUNT(m.id) ...?

@JCMais commented on GitHub (Aug 18, 2016): Can you try `SELECT COUNT(m.id) ...`?
Author
Owner

@olexp commented on GitHub (Aug 18, 2016):

It works on m.product in 2.5.0 and 2.5.4.
Is it expected behavior? Whatever ZfcDatagrid gets is QueryBuilder instance and it may too much work to detect how to count entities.

@olexp commented on GitHub (Aug 18, 2016): It works on m.product in 2.5.0 and 2.5.4. Is it expected behavior? Whatever ZfcDatagrid gets is QueryBuilder instance and it may too much work to detect how to count entities.
Author
Owner

@dtdigio commented on GitHub (Nov 27, 2017):

I have the same issue using FOSElasticaBundle. Like pointed out in #4541, there is a change that fixes this. Reverting commit 097840d. But this may break other things. Are there any plans to fix this in the near future?

@dtdigio commented on GitHub (Nov 27, 2017): I have the same issue using FOSElasticaBundle. Like pointed out in #4541, there is a change that fixes this. Reverting commit 097840d. But this may break other things. Are there any plans to fix this in the near future?
Author
Owner

@lcobucci commented on GitHub (Nov 27, 2017):

This seems to be related to https://github.com/doctrine/doctrine2/pull/6701 but kind of unsure, could someone send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing.

You can find examples on 388afb46d0/tests/Doctrine/Tests/ORM/Functional/Ticket

@lcobucci commented on GitHub (Nov 27, 2017): This seems to be related to https://github.com/doctrine/doctrine2/pull/6701 but kind of unsure, could someone send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing. You can find examples on https://github.com/doctrine/doctrine2/tree/388afb46d0cb3ed0c51332e8df0de9e942c2690b/tests/Doctrine/Tests/ORM/Functional/Ticket
Author
Owner

@olexp commented on GitHub (Mar 31, 2020):

I hit it again. I've created test for 2.7 branch 6a25221328

@olexp commented on GitHub (Mar 31, 2020): I hit it again. I've created test for 2.7 branch https://github.com/olexp/orm/commit/6a25221328c3c2f98cbeb590f2a02f403aa1d886
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5224