OneToOne relation is not updated if proxy is loaded afterwords #6548

Open
opened 2026-01-22 15:34:51 +01:00 by admin · 0 comments
Owner

Originally created by @aurelijusrozenas on GitHub (Sep 23, 2020).

Hi,

TLDR; If parent->child relation is changed when child is still proxy object, and then child proxy is loaded, it will reset parent->child relation to previous state. Run the tests and check the failing test.

I stumbled on some interesting bug. After chasing it for a while I managed to reproduce it and since there is no explanation in the docs that it is the intended functionality I think it's a bug.
How to reproduce it:

  • There are two entities Parent and Child with OneToOne relation
  • Set different child to Parent->child
  • Load proxy for old child
  • The first change is not reflected any more and Parent->child relation is restored to old one.

Now, I do not know how to proceed with problem in my code with similar situation because in my mind I should not worry about whether the entity is proxy or not, the outcome should be always the same. Please help me because I am going crazy... :)

I added test: a6f67ceba5
Try it out:
P.S. The test itself is pretty crappy, sorry about that, you must run one test at a time, not the whole file. It does show the problem though.

git clone --single-branch --branch one-to-one-relation-proxy-bug git@github.com:aurelijusrozenas/orm.git
cd orm
composer install
# This will work, great
./vendor/bin/phpunit /home/infro/dev/orm/tests/Doctrine/Tests/ORM/Functional/Ticket/MyProxyOneToOneRelationTest.php --filter Doctrine\\\\Tests\\\\Functional\\\\Ticket\\\\MyProxyOneToOneRelationTest::testOneToOneRelationChangeWithoutProxyLoad
# This will fail
./vendor/bin/phpunit /home/infro/dev/orm/tests/Doctrine/Tests/ORM/Functional/Ticket/MyProxyOneToOneRelationTest.php --filter Doctrine\\\\Tests\\\\Functional\\\\Ticket\\\\MyProxyOneToOneRelationTest::testOneToOneRelationChangeBeforeProxyLoad

I tried multiple doctrine versions, it seems the outcome is always the same.

Originally created by @aurelijusrozenas on GitHub (Sep 23, 2020). Hi, TLDR; If parent->child relation is changed when child is still proxy object, and then child proxy is loaded, it will reset parent->child relation to previous state. Run the tests and check the failing test. I stumbled on some interesting bug. After chasing it for a while I managed to reproduce it and since there is no explanation in the docs that it is the intended functionality I think it's a bug. How to reproduce it: - There are two entities Parent and Child with OneToOne relation - Set different child to Parent->child - Load proxy for old child - The first change is not reflected any more and Parent->child relation is restored to old one. Now, I do not know how to proceed with problem in my code with similar situation because in my mind I should not worry about whether the entity is proxy or not, the outcome should be always the same. Please help me because I am going crazy... :) I added test: https://github.com/aurelijusrozenas/orm/commit/a6f67ceba5d1ab040d8f0e681c2359931fd9a56a Try it out: P.S. The test itself is pretty crappy, sorry about that, you must run one test at a time, not the whole file. It does show the problem though. ``` git clone --single-branch --branch one-to-one-relation-proxy-bug git@github.com:aurelijusrozenas/orm.git cd orm composer install # This will work, great ./vendor/bin/phpunit /home/infro/dev/orm/tests/Doctrine/Tests/ORM/Functional/Ticket/MyProxyOneToOneRelationTest.php --filter Doctrine\\\\Tests\\\\Functional\\\\Ticket\\\\MyProxyOneToOneRelationTest::testOneToOneRelationChangeWithoutProxyLoad # This will fail ./vendor/bin/phpunit /home/infro/dev/orm/tests/Doctrine/Tests/ORM/Functional/Ticket/MyProxyOneToOneRelationTest.php --filter Doctrine\\\\Tests\\\\Functional\\\\Ticket\\\\MyProxyOneToOneRelationTest::testOneToOneRelationChangeBeforeProxyLoad ``` I tried multiple doctrine versions, it seems the outcome is always the same.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6548