Skip to content

FilterEagerLoadingExtension doesn't properly handle entities that contain foreign identifier #4041

Description

@Edvinas9

API Platform version(s) affected: 2.6.0

Description
If the entity has a foreign identifier (for example @Id property is also a @OneToOne relation) - selectors in the generated DQL should be formatted with IDENTITY(alias.identifier) instead of just alias as FilterEagerLoadingExtension does now.

How to reproduce

  1. Create an entity that has a property that is identifier and a relation at the same time.
  2. Expose GET colection endpoint (@ApiResource)
  3. Add @SearchFilter to some another subproperty
  4. Make a request with a subproperty filter
class Basket
{
    /**
     * @ORM\Id()
     * @ORM\OneToOne(targetEntity="Device")
     */
    private $device;
    
    /**
     * @ApiFilter(SearchFilter::class, properties={"user.email": "exact"})
     */
    private $user
}

Request will fail with the following error:
[Semantical Error] line 0, col 76 near 'o IN(SELECT o_a2': Error: Invalid PathExpression. Must be a StateFieldPathExpression

Possible Solution
FilterEagerLoadingExtension should check if the entity contains foreign identifier & if it does - format selectors differently.

Pull request with a proposed fix will be submitted shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions