mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
[Bug] Relation can't be changed if you fetch an entity and also a collection of its related entities #5961
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 @grongor on GitHub (May 3, 2018).
Hello,
if I fetch an entity with its collection initialized (like eager fetch but in one query), like so:
and then I try to change the relation (change server's customer to a different one or set it to
null), then it doesn't work - ORM generates an empty transaction.I created a repo with a minimalistic example of this behavior: https://github.com/grongor/doctrine-bug-tmp
You can run it yourself, but for your convenience, I already provided output and the diff between the two tests.
@Ocramius commented on GitHub (May 8, 2018):
What's the failing assertion in your code? Also: can it be ported to the ORM test suite?
@grongor commented on GitHub (May 8, 2018):
Well, it's a proof of the bug :D I assert that the results from the query are the same as the state of entities before
flush(). The assert fails becauseflush()doesn't persist the state as it should.I'll look into moving it to the ORM test suite.
@Ocramius commented on GitHub (May 8, 2018):
I was asking which assertion specifically failed in the example code (the first failure).
Still, having the failure in the ORM test suite would allow us to fiddle around with the issue. See https://github.com/doctrine/doctrine2/tree/master/tests/Doctrine/Tests/ORM/Functional/Ticket for examples.
@grongor commented on GitHub (May 8, 2018):
Sorry, I didn't catch that ... code with the bug is
testNotWorking.phpand in its outputtestNotWorking__output.txtyou can see which assert it is and on which line - it's the last one (asserting that actual data in the database are as expected, afterflush().And yeah, I will look into moving it to the ORM test suite :) This was a quick hack, at first to only minimize the code.
@Ocramius commented on GitHub (May 8, 2018):
Hmm, that assertion seems to be wrong:
4f423df143/src/testNotWorking.php (L37-L46)Also, DBAL does not support
PDO::FETCH_KEY_PAIR, so maybe that's where the misunderstanding is.@grongor commented on GitHub (May 8, 2018):
What seems wrong with it? I don't see anything bad there ...
Also
PDO:FETCH_KEY_PAIRworks quite well even though it's not supported.Anyway, I updated the code and removed it. It didn't have any effect whatsoever - the bug is still there. You can check it here:
448a80a4d8I will look into ORM test suite asap (I have my hands full atm, sorry).
@grongor commented on GitHub (May 8, 2018):
Ok so here is the PR with the test case: https://github.com/doctrine/doctrine2/pull/7217
I found out two thigs:
indexBy="id"inand selection of multiple entities and left-joining them in
If you remove either one then the test case won't fail.
@Ocramius commented on GitHub (May 8, 2018):
Aha, I didn't see the
indexByat all.@grongor commented on GitHub (May 8, 2018):
Yeah, and I didn't think it was related at all (to be honest, I kinda forgotten about it :D ) until I somehow stumbled over it and noticed that it is part of the problem :D