StofDoctrineExtensionsBundle
StofDoctrineExtensionsBundle copied to clipboard
Softdeleteable ODM isn't going to work
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
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
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.