DDC-3754: Entity cloning #4603

Closed
opened 2026-01-22 14:45:48 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 3, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user mastir:

Sometimes doctrine query results proxy objects, even if them loaded directly. Proxy class overriding __clone method, so i can't reset id fields for it.I used another method "__clone_again_for_random_proxified_entity" to reset image id, but i'm sure its not the way this shuld work.
My code as example:

             $imgs = $this->getService('doctrine')->getQueryBuilder()
                    ->select('i')
                    ->from('Page\\Image', 'i')
                    ->where('i.page=:p')
                    ->getQuery()
                    ->setParameter('p',$source)
                    ->getResult();
                foreach($imgs as $img){
                    $copy = clone $img;
                    if(is*callable([$img, '_*isInitialized'])){ //is a proxy
                        $copy->*_clone_again_for_random_proxified*entity();
                    }
                    $entity->addPart($copy);
                }

i wasted half of day to catch collction with proxified entity (i think its loaded some where before as a proxy and then initialized on query)
i think its easy to fix by adding parent::**clone call on a proxy objects and avoid this kind of bugs. Thanks.

Originally created by @doctrinebot on GitHub (Jun 3, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user mastir: Sometimes doctrine query results proxy objects, even if them loaded directly. Proxy class overriding __clone method, so i can't reset id fields for it.I used another method "__clone_again_for_random_proxified_entity" to reset image id, but i'm sure its not the way this shuld work. My code as example: ``` $imgs = $this->getService('doctrine')->getQueryBuilder() ->select('i') ->from('Page\\Image', 'i') ->where('i.page=:p') ->getQuery() ->setParameter('p',$source) ->getResult(); foreach($imgs as $img){ $copy = clone $img; if(is*callable([$img, '_*isInitialized'])){ //is a proxy $copy->*_clone_again_for_random_proxified*entity(); } $entity->addPart($copy); } ``` i wasted half of day to catch collction with proxified entity (i think its loaded some where before as a proxy and then initialized on query) i think its easy to fix by adding parent::**clone call on a proxy objects and avoid this kind of bugs. Thanks.
admin added the Bug label 2026-01-22 14:45:48 +01:00
admin closed this issue 2026-01-22 14:45:48 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jun 3, 2015):

Comment created by @ocramius:

parent::**clone should actually be in the proxies. If that's not the case, then please write a test case against https://github.com/doctrine/common

See also ff72726b08/tests/Doctrine/Tests/Common/Proxy/ProxyMagicMethodsTest.php (L216-L231)

@doctrinebot commented on GitHub (Jun 3, 2015): Comment created by @ocramius: `parent::**clone` should actually be in the proxies. If that's not the case, then please write a test case against https://github.com/doctrine/common See also https://github.com/doctrine/common/blob/ff72726b0876638fa7db2f28b0f26e3f1f6656ca/tests/Doctrine/Tests/Common/Proxy/ProxyMagicMethodsTest.php#L216-L231
Author
Owner

@doctrinebot commented on GitHub (Jun 3, 2015):

Comment created by mastir:

Manual proxy regeneration solved this problem. Thanks a lot.

@doctrinebot commented on GitHub (Jun 3, 2015): Comment created by mastir: Manual proxy regeneration solved this problem. Thanks a lot.
Author
Owner

@doctrinebot commented on GitHub (Jun 3, 2015):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Jun 3, 2015): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4603