Symfony2 Doctrine SoftDeletable and JMSSerializerBundle not working together

I use the Gedmo SoftDeletable filter for Symfony2 and Doctrine ( https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/softdeleteable.md )

I also use JMSSerializerBundle to serialize reponses for JSON for my REST API.

As soon as I “disconnect” a company, my function to request all companies no longer works, because it throws an Entity not Found exception ... Is there a way to make sure that the JMSSerializerBundle ignores soft deals in my database?

The my all () function looks like this:

/** * All action * @return array * * @Rest\View */ public function allAction() { $em = $this->getDoctrine()->getManager(); $entities = $em->getRepository('TestCRMBundle:Company')->findAll(); return array( 'companies' => $entities, ); } 
+4
source share
2 answers

need to add to config

  orm: filters: softdeleteable: class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter enabled: true 

and add to objects

 use Gedmo\Mapping\Annotation as Gedmo; * @ORM\HasLifecycleCallbacks * @Gedmo\SoftDeleteable(fieldName="deletedAt") 
+1
source

It is currently not supported due to nested relationships, now you can do nothing.

However, you can disable SoftDeletable behavior:

 /** * All action * @return array * * @Rest\View */ public function allAction() { $em = $this->getDoctrine()->getManager(); $em->getFilters()->disable('softdeletable'); // Disable the filter $entities = $em->getRepository('TestCRMBundle:Company')->findAll(); return array( 'companies' => $entities, ); } 

Being warned, it will return ALL objects, even DELETED .

+3
source

All Articles