Skip to content

Wrong DQL generation for boolean filter on nested property #2645

Description

@vasilvestre

Having an entity like this

User
    Childs (one-to-many-self of User)
    Codes (one to many of User)
        isEnabled (boolean)

Using a boolean filter
/user?childs.codes.isEnabled=false
The result of this contain entity that have isEnabled set to true on codes entity.

The generated DQL create a IN condition that retrieve the same data (with false or true).
It look like this :

SELECT r0_.id AS id_0
FROM User r0_
       INNER JOIN Childs r1_ ON r0_.id = r1_.parent_id
       INNER JOIN Codes r2_ ON r1_.id = r2_.user_id
WHERE r0_.id IN (SELECT r3_.id
                 FROM User_ r3_
                        INNER JOIN Childs_ r4_ ON r3_.id = r4_.parent_id
                        INNER JOIN Codes_ r5_ ON r4_.id = r5_.user_id
                 WHERE r5_.is_enabled = false)
ORDER BY r0_.id ASC;

The SQL should use NOT IN (seem like a bad practice) or this

SELECT r0_.id AS id_0
FROM User r0_
       INNER JOIN Childs r1_ ON r0_.id = r1_.parent_id
       INNER JOIN Codes r2_ ON r1_.id = r2_.user_id
WHERE r2_.is_enabled=false
ORDER BY r0_.id ASC;

With api platform/core 2.4

Some through :

  • The SQL keep at least one of the Childs so the paginator get back all childs and codes even those that are disabled

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions