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

OneToMany with fetch=EAGER fails #271

Open
BenoitDuffez opened this issue Jun 5, 2024 · 0 comments
Open

OneToMany with fetch=EAGER fails #271

BenoitDuffez opened this issue Jun 5, 2024 · 0 comments
Labels

Comments

@BenoitDuffez
Copy link

BenoitDuffez commented Jun 5, 2024

Similar to #264 but triggered with a join on two tables.

Description

Say you have entities A, B, and A has a OneToMany relation with B. I wanted to avoid multiple db lookups so I have added fetch: 'EAGER' on A's OneToMany attribute.

Steps to reproduce

Create 2 entities with binary uuid IDs and link them with a OneToMany relation with fetch: 'EAGER'

Expected behavior

Looking up A and all its B's would be done in one query.

Screenshots or output

Actual behavior: crash on vendor/doctrine/orm/src/Persisters/Entity/BasicEntityPerister.php:1911:

UnhandledMatchError
HTTP 500 Internal Server Error
Unhandled match case 16

private function getArrayBindingType(ParameterType|int|string $type): ArrayParameterType|int
{
    if (! $type instanceof ParameterType) {
        $type = Type::getType((string) $type)->getBindingType();
    }
    return match ($type) {
        ParameterType::STRING => ArrayParameterType::STRING,
        ParameterType::INTEGER => ArrayParameterType::INTEGER,
        ParameterType::ASCII => ArrayParameterType::ASCII,
    };
}

In our case $type is 16, which is ParameterType::BINARY.

Environment details

  • version of this package: 2.0.0
  • PHP version: 8.3
  • OS: Ubuntu 24.04

Additional context

Changing the function above with this:

private function getArrayBindingType(ParameterType|int|string $type): ArrayParameterType|int
{
    if (! $type instanceof ParameterType) {
        $type = Type::getType((string) $type)->getBindingType();
    }
    return match ($type) {
        ParameterType::STRING, ParameterType::BINARY => ArrayParameterType::STRING,
        ParameterType::INTEGER => ArrayParameterType::INTEGER,
        ParameterType::ASCII => ArrayParameterType::ASCII,
    };
}

solves both problems:

  1. it works
  2. there are 7 queries on my page vs 9 before, showing that eagerly fetching (e.g. joining tables on the 1st query) optimizes db access and increase performance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant