Please help with SuperClass #5572

Closed
opened 2026-01-22 15:11:38 +01:00 by admin · 9 comments
Owner

Originally created by @andrconstruction on GitHub (Jun 8, 2017).

Originally assigned to: @andrconstruction on GitHub.

https://pastebin.com/KvGn3KZZ
When I try to update entity ( preUpdate event ), in this case all work fine, because updated only useMod field, but if I try to add a new entity, and fired a prePersist event where updated both fields userCreate and userUpdate I got an error, than a new entity was found throug a relashionship Card#userCreate, what may be wrong? doctrine 2

Originally created by @andrconstruction on GitHub (Jun 8, 2017). Originally assigned to: @andrconstruction on GitHub. https://pastebin.com/KvGn3KZZ When I try to update entity ( preUpdate event ), in this case all work fine, because updated only useMod field, but if I try to add a new entity, and fired a prePersist event where updated both fields userCreate and userUpdate I got an error, than a new entity was found throug a relashionship Card#userCreate, what may be wrong? doctrine 2
admin added the IncompleteMissing TestsQuestion labels 2026-01-22 15:11:38 +01:00
admin closed this issue 2026-01-22 15:11:38 +01:00
Author
Owner

@Ocramius commented on GitHub (Jun 9, 2017):

@andrconstruction a practical code example is needed - I didn't understand what the problem is here...

@Ocramius commented on GitHub (Jun 9, 2017): @andrconstruction a practical code example is needed - I didn't understand what the problem is here...
Author
Owner

@andrconstruction commented on GitHub (Jun 9, 2017):

entities here : https://pastebin.com/KvGn3KZZ

and preUpdate prePersist


 public function prePersist( $ea ) {
            $object = $ea->getObject();

            if ( $object instanceof AshAbstractEntity ) {
                $currentUser = $ea->getObjectManager()->getReference( User::class, $this->getAuthService()->getIdentity()->getId() );
                $currentUser2 = $ea->getObjectManager()->find( User::class, $this->getAuthService()->getIdentity()->getId() );

                $object->setUserCreate( $currentUser );
                $object->setUserMod( $currentUser2 );
                $object->setCreated( new \DateTime() );
                $object->setUpdated( new \DateTime() );
            }
        }

        public function preUpdate( PreUpdateEventArgs $ea ) {
            $object = $ea->getObject();
            if ( $object instanceof AshAbstractEntity ) {
                $c = $this->getAuthService()->getIdentity();
                
                $currentUser = $ea->getObjectManager()->getReference( User::class, $this->getAuthService()->getIdentity()->getId() );
                $object->setUserMod( $currentUser );
                $object->setVersion( $object->getVersion() + 1 );
                $object->setUpdated( new \DateTime() );
            }
        }
@andrconstruction commented on GitHub (Jun 9, 2017): entities here : https://pastebin.com/KvGn3KZZ and preUpdate prePersist ``` public function prePersist( $ea ) { $object = $ea->getObject(); if ( $object instanceof AshAbstractEntity ) { $currentUser = $ea->getObjectManager()->getReference( User::class, $this->getAuthService()->getIdentity()->getId() ); $currentUser2 = $ea->getObjectManager()->find( User::class, $this->getAuthService()->getIdentity()->getId() ); $object->setUserCreate( $currentUser ); $object->setUserMod( $currentUser2 ); $object->setCreated( new \DateTime() ); $object->setUpdated( new \DateTime() ); } } public function preUpdate( PreUpdateEventArgs $ea ) { $object = $ea->getObject(); if ( $object instanceof AshAbstractEntity ) { $c = $this->getAuthService()->getIdentity(); $currentUser = $ea->getObjectManager()->getReference( User::class, $this->getAuthService()->getIdentity()->getId() ); $object->setUserMod( $currentUser ); $object->setVersion( $object->getVersion() + 1 ); $object->setUpdated( new \DateTime() ); } } ```
Author
Owner

@andrconstruction commented on GitHub (Jun 9, 2017):

If I will make without a superclass, move userMod and userCreate attributes into the Card Entity all works fine and save

@andrconstruction commented on GitHub (Jun 9, 2017): If I will make without a superclass, move userMod and userCreate attributes into the Card Entity all works fine and save
Author
Owner

@andrconstruction commented on GitHub (Jun 15, 2017):

Is anybody help?

@andrconstruction commented on GitHub (Jun 15, 2017): Is anybody help?
Author
Owner

@andrconstruction commented on GitHub (Nov 7, 2017):

Marcoooo......It is actual at the moment yet

@andrconstruction commented on GitHub (Nov 7, 2017): Marcoooo......It is actual at the moment yet
Author
Owner

@lcobucci commented on GitHub (Nov 26, 2017):

@andrconstruction it would be 100% easier for us to help you if you could send us a failing test case that reproduces that behaviour, can you please do that?

You can find examples on 388afb46d0/tests/Doctrine/Tests/ORM/Functional/Ticket

@lcobucci commented on GitHub (Nov 26, 2017): @andrconstruction it would be 100% easier for us to help you if you could send us a failing test case that reproduces that behaviour, can you please do that? You can find examples on https://github.com/doctrine/doctrine2/tree/388afb46d0cb3ed0c51332e8df0de9e942c2690b/tests/Doctrine/Tests/ORM/Functional/Ticket
Author
Owner

@razbakov commented on GitHub (Sep 6, 2018):

@andrconstruction which error do you have?

@razbakov commented on GitHub (Sep 6, 2018): @andrconstruction which error do you have?
Author
Owner

@Ocramius commented on GitHub (Sep 6, 2018):

Closing as incomplete here

@Ocramius commented on GitHub (Sep 6, 2018): Closing as incomplete here
Author
Owner

@andrconstruction commented on GitHub (Sep 8, 2018):

I figured out in the my problem. Just fired a lot of listeners and each add same object after persist. Remove duplicated functions solve this exception. Thanks to all responders

@andrconstruction commented on GitHub (Sep 8, 2018): I figured out in the my problem. Just fired a lot of listeners and each add same object after persist. Remove duplicated functions solve this exception. Thanks to all responders
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5572