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::indexBy no longer works when refering a database column #11097

Closed
aprat84 opened this issue Nov 30, 2023 · 3 comments · Fixed by #11380
Closed

OneToMany::indexBy no longer works when refering a database column #11097

aprat84 opened this issue Nov 30, 2023 · 3 comments · Fixed by #11380

Comments

@aprat84
Copy link
Contributor

aprat84 commented Nov 30, 2023

BC Break Report

Q A
BC Break yes
Version 2.17.0

Summary

Indexing by database column worked, now it doesn't.
Better look at previous/current behavior.

Previous behavior

class Language
{
    #[ORM\Id]
    #[ORM\Column(type: 'string', length: 20)]
    private ?string $id = null;
}

class Product {
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer', options: ['unsigned' => true])]
    private ?int $id = null;

    #[ORM\OneToMany(
        mappedBy: 'product',
        targetEntity: ProductTranslation::class,
        cascade: ['persist', 'merge'],
        fetch: 'EAGER',
        indexBy: 'language_id'
    )]
    private Collection $translations;
}

class ProductTranslation {
    #[ORM\Id]
    #[ORM\ManyToOne(targetEntity: Product::class, inversedBy: 'translations')]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private Product $product;

    #[ORM\Id]
    #[ORM\ManyToOne(targetEntity: Language::class)]
    #[ORM\JoinColumn(nullable: false)]
    private Language $language;
}

This worked, indexing Product::$translations by language_id (Language::$id).

Current behavior

I get a warning and an error:

Warning: Undefined array key "language_id"
vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php:846
Error: Call to a member function getValue() on null
vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:3195

How to reproduce

I've created a simple symfony project: https://github.com/aprat84/doctrine-2.17-bug

  • Clone it
  • Execute migrations
  • Execute tests in each commit (one for 2.16.3 and one for 2.17.1)
@aprat84 aprat84 changed the title OneToMany::indexBy no longer works when refering a ToOne relation's id OneToMany::indexBy no longer works when refering a database column Nov 30, 2023
@aprat84
Copy link
Contributor Author

aprat84 commented Dec 1, 2023

Added a repo with simple project to reproduce the bug:
https://github.com/aprat84/doctrine-2.17-bug

@igoooor
Copy link

igoooor commented Mar 18, 2024

Have you found a solution or a workaround to this? I have the same issue and don't know how to proceed

@aprat84
Copy link
Contributor Author

aprat84 commented Apr 26, 2024

This is fixed by #11380

@aprat84 aprat84 closed this as completed Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants