StofDoctrineExtensionsBundle icon indicating copy to clipboard operation
StofDoctrineExtensionsBundle copied to clipboard

Softdeleteable ODM isn't going to work

Open dgruseck opened this issue 11 years ago • 2 comments

Hi,

I'm trying to configure the softdeletable feature for my odm document.

My configuration looks like this:

config.yml

doctrine_mongodb:
    connections:
        default:
            ...
    document_managers:
        default:
            filters:
                softdeleteable:
                        class: Gedmo\SoftDeleteable\Filter\ODM\SoftDeleteableFilter
                        enabled: true

stof_doctrine_extensions:
    orm:
        default: 
            timestampable: true
            sluggable: true
    mongodb:
        default: 
            timestampable: true
            #Without this I get a "Listener “SoftDeleteableListener” was not added to the EventManager" error (Not in ORM)
            softdeleteable: true

service.yml

    gedmo.listener.softdeleteable:
        class: Gedmo\SoftDeleteable\SoftDeleteableListener
        tags:
            - { name: doctrine.odm.mongodb.default_event_subscriber }
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ @annotation_reader ] ]

Document

/**
 * @MongoDB\Document(db="test", collection="pictures")
 * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
 */
class Picture
{
    ...
    /**
     * @MongoDB\Date
     */
    protected $deletedAt;

    ...

    /**
     * Set deletedAt
     *
     * @param date $deletedAt
     * @return self
     */
    public function setDeletedAt($deletedAt)
    {
        $this->deletedAt = $deletedAt;
        return $this;
    }

    /**
     * Get deletedAt
     *
     * @return date $deletedAt
     */
    public function getDeletedAt()
    {
        return $this->deletedAt;
    }
}

If I remove the config for softdeletable fetching and removing is working properly.

But with the softdeleteable feature on I can't fetch any pictures and if I try to remove one I get following error: No mapping found for field 'deletedAt' in class 'Tes\StoreBundle\Document\Picture'.

Am I doing somethin wrong?

Thanks, David

dgruseck avatar Feb 22 '14 13:02 dgruseck

why are you trying to register the listener yourself ? It is what the bundle is doing.

Anyway, doctrine.odm.mongodb.default_event_subscriber is the wrong tag name for the ODM, so your own service is not registered as a listener for the ODM

stof avatar Mar 05 '14 00:03 stof

Thanks,

is it the correct behavior that deletedAt is set but all select statements returns the deleted document? Because the DoctrineExtensions list the softdeleatable feature only works for orm.

dgruseck avatar Mar 07 '14 08:03 dgruseck