Question

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

I'm also using the JMSSerializerBundle to serialize reponses to JSON for my REST API.

As soon as I "softdelete" a company my function to request all companies doesn't work anymore because it throws a Entity not Found exception... Is there any way to make sure that JMSSerializerBundle ignores the softdeleted entities in my Database?

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,
    );
}
Was it helpful?

Solution 2

need to add to config

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

and add to entities

use Gedmo\Mapping\Annotation as Gedmo;

 * @ORM\HasLifecycleCallbacks
 * @Gedmo\SoftDeleteable(fieldName="deletedAt")

OTHER TIPS

It is currently not supported because of the nested relationship, there is nothing you can do for now.

However, you may disable the 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,
    );
}

Be warned, it will return ALL, even DELETED entities.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top