Symfony2 / Doctrine: Reading "Remote" Data Using Gedmo Doctrine Extensions

I am creating a Symfony2 project and using gedmo/doctrine-extensions ( GitHub ) to implement soft deletion. My question is: is there a way to "disable" or "override" softdelete, or even detect that something has been softly deleted.

Here's the situation:

I have a "note" object that references a "custom" object. A specific note mentions a user who has been deleted from a soft point. Although the user has been deleted, it returns true for TWIG "defined" and may even return the identifier of the remote user. However, if I request any other information (including the "deletedAt" parameter, which indicates whether it was deleted), I get an 500 "Entity was not found" error.

Since the data actually still exists, and since the note itself has not been deleted, I still want to say who wrote the note, even though the user was deleted.

Is it possible? If not, how to correctly determine if something has been gently removed? As I said, $note->getUser() still retrieves the object and returns true for any null / "specific" matches.

+7
symfony doctrine soft-delete
source share
3 answers

You need to set the relationship loading on eager , this will prevent lazy loading of objects with just id and nothing more.

More information about the download you can find here:

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-objects.html#by-eager-loading

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html

As for my code, here is what it looks like when defining a User link now:

 /** * @ORM\ManyToOne(targetEntity="User", inversedBy="answers", fetch="EAGER") * @ORM\JoinColumn(name="user_id", referencedColumnName="id") */ private $user; 

In this case, the User object may have multiple answers . When loading User in terms of answer this will work:

 foreach($answers as $answer) { $user = $answer->getUser(); if (!$user) { continue; } } 
+6
source share

You can do it:

 $filter = $em->getFilters()->enable('soft-deleteable'); $filter->disableForEntity('Entity\User'); $filter->enableForEntity('Entity\Note'); 
+14
source share

You can temporarily disable soft-delete so that deleted items are returned in the results. See the documentation , the section that reads is especially interesting to you:

This will disable the SoftDeleteable filter, so objects that were "soft-deleted" will appear in the results $ -> getFilters () → disable ('soft deleteable');

So, first run the code above in your $em Entity Manager, and then use it to collect $note .

+1
source share

All Articles