logo
down
shadow

Preserving changes made to a document with Doctrine's PreUpdate lifecycle event


Preserving changes made to a document with Doctrine's PreUpdate lifecycle event

By : user2955689
Date : November 22 2020, 10:40 AM
Does that help You cannot modify the fields directly in the preUpdate event, you have to modify their primitive values. Changes to associations are not allowed. You would have to do:
code :
$eventArgs->setNewValue('fooCode', 'Salamanders');
// inserts a new entity into the database
$document = new Document();
$document->setName('My Document');

$em->persist($document);
$em->flush();
// retrieves entity from the database, makes a change, then updates the database
$document = $em->findOneByName('My Document');
$document->setFooCode('Salamanders');

$em->flush();


Share : facebook icon twitter icon
NHibernate, joined subclass hierarchy, PreUpdate event data changes on an entity which is only modified in the PreUpdate

NHibernate, joined subclass hierarchy, PreUpdate event data changes on an entity which is only modified in the PreUpdate


By : user2903409
Date : March 29 2020, 07:55 AM
it should still fix some issue To answer this I have authored an nhibernate.info WIKI article - http://nhibernate.info/doc/howto/various/changing-values-in-nhibernate-events
The abstract; Audit trails using NHibernate's event model often use the OnPreInsert and OnPreUpdate event listeners to change/ modify the state of the entity. While this does works and is widely documented as a solution, it should be noted the OnPreInsert and OnPreUpdate events are not intended to be used to change the values of the entity and instead they should be used to check values and for that reason they return "veto".
Symfony2: File Upload via Doctrine does not fire the PrePersist/PreUpdate lifecycle-event

Symfony2: File Upload via Doctrine does not fire the PrePersist/PreUpdate lifecycle-event


By : user3496362
Date : March 29 2020, 07:55 AM
With these it helps You need to change tracking policies.
Full explanation.
Symfony2: PrePersist/PreUpdate lifecycle-event not fired

Symfony2: PrePersist/PreUpdate lifecycle-event not fired


By : Sami
Date : March 29 2020, 07:55 AM
it should still fix some issue The first time you call persist doctrine will only save $album and not its images. You must specify that you want doctrine to cascade the persist by specifying it in the $images declaration:
code :
    /**
     * @ORM\OneToMany(targetEntity="GalleryImage", mappedBy="parent", cascade={"persist", "remove"})
     */
    protected $images;
Altering another document in Doctrine ODM PreUpdate event

Altering another document in Doctrine ODM PreUpdate event


By : teletobi
Date : March 29 2020, 07:55 AM
Hope that helps
Tried recomputeSingleDocumentChangeSet on the unit of work for the user, but this doesn't seem to save anything.
code :
$user->setSomething(true);
$uow->recomputeSingleDocumentChangeSet(/* ... */);
Creating/persisting new document while preUpdate event in doctrine-mongodb

Creating/persisting new document while preUpdate event in doctrine-mongodb


By : Kritchai Phromros
Date : March 29 2020, 07:55 AM
wish helps you I created a test case for your use case here. One thing that stood out from the code in your question was that you weren't calling recomputeSingleDocumentChangeSet() on the document you were modifying during the lifecycle callback, as is mentioned in the preUpdate documentation. But even with that call, the new document will not be inserted. This is due to the fact that UnitOfWork executes updates after insertions and upserts. The full order can be seen in UnitOfWork's commit() method:
Document upserts Document inserts Document updates Extra updates (scheduled internally by persister classes) Collection deletions Collection updates Document deletions
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org