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

Duplicate objects in collection of nested objects with multiple references #9579

Closed
klammbueddel opened this issue Mar 10, 2022 · 1 comment

Comments

@klammbueddel
Copy link

klammbueddel commented Mar 10, 2022

Bug Report

Given 3 classes, a Container containing a list of Items and each item containing multiple Parts, if the container references both, the complete list of items ($container->items) and points to one item in the list ($container->currentItem), the parts of the item will be duplicated in the result set if fetched via DQL.

As a sidenote, the issue does not occur if the objects are already managed (see testIfAlreadyManaged in #9580).

Q A
BC Break no
Version 2.11.2

How to reproduce

$container = new Container();

# a container has items
$item = new Item();
$item->container = $container;
$container->items[]= $item;

# the container has a pointer on one item in the list of items
$container->currentItem = $item;

# an item has parts
$part = new Part();
$part->item = $item;
$item->parts[] = $part

$dql = <<<DQL
SELECT container, currentItem, currentItemPart, item, itemPart 
FROM Container container
LEFT JOIN container.currentItem currentItem
LEFT JOIN currentItem.parts currentItemPart  
LEFT JOIN container.items item 
LEFT JOIN item.parts itemPart
DQL;

# this test will fail
$containers = $this->_em->createQuery($dql)->execute();
self::assertCount(1, $containers);
self::assertCount(1, $containers[0]->items);
self::assertCount(1, $containers[0]->items[0]->parts); # << the item will contain 2 parts

Expected behavior

The $item->parts should not contain duplicates.

klammbueddel pushed a commit to klammbueddel/orm that referenced this issue Mar 10, 2022
klammbueddel pushed a commit to klammbueddel/orm that referenced this issue Mar 10, 2022
klammbueddel pushed a commit to klammbueddel/orm that referenced this issue Mar 10, 2022
klammbueddel pushed a commit to klammbueddel/orm that referenced this issue Mar 11, 2022
klammbueddel pushed a commit to klammbueddel/orm that referenced this issue Mar 11, 2022
klammbueddel pushed a commit to klammbueddel/orm that referenced this issue Mar 11, 2022
klammbueddel pushed a commit to klammbueddel/orm that referenced this issue Mar 11, 2022
@klammbueddel
Copy link
Author

Hi,
would be great if somebody could review the PR.
Thanks ;)

klammbueddel pushed a commit to klammbueddel/orm that referenced this issue Mar 18, 2022
klammbueddel pushed a commit to klammbueddel/orm that referenced this issue Mar 18, 2022
klammbueddel pushed a commit to klammbueddel/orm that referenced this issue Mar 18, 2022
greg0ire added a commit that referenced this issue Mar 18, 2022
n-e-m-a-nj-a pushed a commit to n-e-m-a-nj-a/orm that referenced this issue Mar 29, 2022
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

2 participants