mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Manual ManyToMany relationship Creating middle class and ManyToOne shows Undefined index: x Error when pulling data from one class. #6462
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mmoradeveloper on GitHub (May 8, 2020).
Bug Report
PHP 7.4.5
Symfony 4.4
"symfony/orm-pack": "^1.0",
"doctrine/doctrine-bundle": "v2.0.8",
"doctrine/orm": "v2.7.2",
Summary
We generate manually a behaviour ManyToMany because we need the ability to generate more content into the middle class. So we have Product Related to Tags. and all we want is to get the list of tags from a call into ProductEntity we receive an Exception: "Notice: Undefined index: tag"
We have the following Classes:
ProductEntity
ProductTagRelationEntity
And the ProductTagEntity`
Current behavior
So when we get a product from a repository call;
$product = $this->productRepository->getBySlug($slug);and when we call the function
$productEntity->getTagsArray();the run stops in the line where we call "title" => $t->getTag()->getTitle(),
But the weirdest thing is that it does not stop in the first entrance it shows the error when the index in the loop is equal 1.
How to reproduce
So if I run a test and do,
that will print :
int(1) int(2) int(3)But if instead I run a test doing
that will print
int(1) string(4) "Tag1" int(2)As you can see and I explain before it stops the execution and through an error on the second Loading.
Expected behavior
Returning an array of multiple tags.
@mmoradeveloper commented on GitHub (May 20, 2020):
A class was missing a OneToOne Relationship