Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Edvinas9 opened this issue Feb 9, 2021 · 0 comments

Comments

@Edvinas9
Copy link
Contributor

Edvinas9 commented Feb 9, 2021

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.

Edvinas9 added a commit to Edvinas9/core that referenced this issue Feb 9, 2021
Edvinas9 added a commit to Edvinas9/core that referenced this issue Feb 9, 2021
alanpoulain pushed a commit to Edvinas9/core that referenced this issue Feb 15, 2021
alanpoulain added a commit that referenced this issue Feb 15, 2021
…#4042)

* Issue #4041 bugfix: FilterEagerLoadingExtension foreign identifier handling

* test: add a unit test and use a foreign id for DummyCar

* chore: add changelog entry

Co-authored-by: Alan Poulain <contact@alanpoulain.eu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant