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

Nested search fields with same relational property name lead to missing JOIN statements #6767

Open
ServerExe opened this issue Jan 28, 2025 · 0 comments

Comments

@ServerExe
Copy link

ServerExe commented Jan 28, 2025

Imagine having the following entities:

class GiroAccount 
{
    #[ORM\Column]
    private string $name;

    /** @var Collection<int, GiroAccountDetail> */
    #[ORM\OneToMany(targetEntity: GiroAccountDetail::class, mappedBy: 'giroAccount')]
    private Collection $details;

    /** @var Collection<int, GiroAccountCard> */
    #[ORM\OneToMany(targetEntity: GiroAccountCard::class, mappedBy: 'giroAccount')]
    private Collection $cards;
}

# ---------------------------

class GiroAccountDetail 
{
    #[ORM\Column]
    private string $name;
}

# ---------------------------

class GiroAccountCard
{
    #[ORM\Column]
    private string $name;

    /** @var Collection<int, GiroAccountCardDetail> */
    #[ORM\OneToMany(targetEntity: GiroAccountCardDetail::class, mappedBy: 'card')]
    private Collection $details;
}

# ---------------------------

class GiroAccountCardDetail
{
    #[ORM\Column]
    private string $name;
}

Now, you can see that there are relational properties with the name "details". This is causing an issue when chaining them in the search fields:

->setSearchFields([
    'name',
    'details.name',
    'cards.details.name',
])

... will simply ignore a JOIN statement for GiroAccount::$details. The query looks like this then:

FROM giro_account g0_
LEFT JOIN giro_account_card g1_ ON g0_.id = g1_.giro_account_id
LEFT JOIN giro_account_card_detail g2_ ON g1_.id = g2_.card_id

... instead of ...

FROM giro_account g0_
LEFT JOIN giro_account_detail g1_ ON g0_.id = g1_.giro_account_id
LEFT JOIN giro_account_card g2_ ON g0_.id = g2_.giro_account_id
LEFT JOIN giro_account_card_detail g3_ ON g2_.id = g3_.card_id
@ServerExe ServerExe changed the title Nested search fields with same property name of relations lead to wrong JOIN statement construction Nested search fields with same relational property name lead to missing JOIN statements Jan 28, 2025
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