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

fix(doctrine): handle inverse side of OneToOne association in Doctrine search filter #4366

Conversation

carlobeltrame
Copy link
Contributor

@carlobeltrame carlobeltrame commented Jul 26, 2021

Q A
Branch? main because @soyuka told me so, but ideally it should be for the current stable branch
Tickets Same as #2049, but for SearchFilter instead of ExistsFilter
License MIT

The same problem explained in #2049 also happens for the Doctrine SearchFilter. This PR fixes the SearchFilter, similarly to how #2051 fixed the ExistsFilter.

The issue can be reproduced by adding an Entity Dummy that has an owning one-to-one relation to another Entity RelatedOwnedDummy, and then adding a SearchFilter for that relation:

/**
 * @ORM\Entity
 */
#[ApiResource]
#[ApiFilter(SearchFilter::class, properties: ['relatedOwnedDummy'])]
class Dummy {

    /**
     * @ORM\OneToOne(targetEntity="RelatedOwnedDummy", mappedBy="owner", cascade={"persist"})
     */
    public ?RelatedOwnedDummy $relatedOwnedDummy = null;

}

Without this fix, Doctrine complains:
"A single-valued association path expression to an inverse side is not supported in DQL queries. Instead of "o.relatedOwnedDummy" use an explicit join."

  • Always add tests and ensure they pass.
  • Never break backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the current stable version branch.
  • Features and deprecations must be submitted against main branch.
  • Legacy code removals go to the main branch.
  • Update CHANGELOG.md file.
  • Follow the Conventional Commits specification.

@carlobeltrame carlobeltrame force-pushed the fix/search-filter-inverse-one-to-one branch 2 times, most recently from a014d7b to f28ed47 Compare July 27, 2021 10:36
@soyuka
Copy link
Member

soyuka commented Aug 10, 2021

Please rebase against main I want to freeze 2.6 from now on.

@carlobeltrame carlobeltrame force-pushed the fix/search-filter-inverse-one-to-one branch from f28ed47 to 1bdfc52 Compare September 4, 2021 15:23
@carlobeltrame carlobeltrame changed the base branch from 2.6 to main September 4, 2021 15:23
@carlobeltrame
Copy link
Contributor Author

@soyuka done

@alanpoulain alanpoulain changed the base branch from main to 2.6 September 27, 2021 15:47
@alanpoulain alanpoulain changed the title Fix Doctrine SearchFilter for inverse side of OneToOne association fix(doctrine): handle inverse side of OneToOne association in Doctrine search filter Sep 27, 2021
This is the equivalent fix for SearchFilter as was done in
api-platform#2049 for the ExistsFilter.
Without this fix, Doctrine complains:
"A single-valued association path expression to an inverse side is not
supported in DQL queries. Instead of \"o.owner\" use an explicit join."
@alanpoulain alanpoulain force-pushed the fix/search-filter-inverse-one-to-one branch from 1bdfc52 to 63c1dc5 Compare September 27, 2021 15:49
@alanpoulain
Copy link
Member

Thank you @carlobeltrame! I will merge 2.6 into main later.

@alanpoulain alanpoulain merged commit 2f2b1c8 into api-platform:2.6 Sep 27, 2021
@carlobeltrame carlobeltrame deleted the fix/search-filter-inverse-one-to-one branch November 23, 2021 20:21
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

Successfully merging this pull request may close these issues.

None yet

3 participants