restsymfonydoctrine-ormjmsserializerbundledoctrine-extensions

Symfony2 Doctrine SoftDeletable and JMSSerializerBundle not working together


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,
    );
}

Solution

  • 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")