我们正在使用Symfony 3.4创建API-REST并使用mongodb作为db
所有的映射和配置都已完成,并且可以正常工作。
... buuuuuuuttt softdeleteable过滤器无法正常工作,我的意思是:
这是我的config.yml:
stof_doctrine_extensions:
default_locale: '%locale%'
mongodb:
default:
timestampable: true
softdeleteable: true
translatable: true
loggable: true
uploadable: true
translation_fallback: true
uploadable:
default_file_path: "%kernel.root_dir%/../web/files/"
# Doctrine Configuration
doctrine_mongodb:
default_database: "%mongodb_default_db%"
document_managers:
default:
retry_connect: 5
retry_query: 5
auto_mapping: true
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\ODM\SoftDeleteableFilter
enabled: true
mappings:
#translatable
gedmo_translatable:
type: annotation
alias: GedmoTranslatable
prefix: Gedmo\Translatable\Document
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Document"
is_bundle: false
#loggable
gedmo_loggable:
type: annotation
alias: GedmoLoggable
prefix: Gedmo\Loggable\Document
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Document"
is_bundle: false
proxy_namespace: MongoDBODMProxies
proxy_dir: "%kernel.cache_dir%/doctrine/odm/mongodb/Proxies"
auto_generate_proxy_classes: '%kernel.debug%'
映射的一个例子:
Example\ExampleBundle\Model\Example:
collection: example
gedmo:
loggable: true
translation:
locale: locale
soft_deleteable:
field_name: deletedAt
time_aware: false
fields:
id:
type: object_id
id: true
name:
type: string
nullable: false
gedmo:
- translatable
- versioned
description:
type: string
nullable: false
gedmo:
- translatable
- versioned
createdAt:
name: created_at
type: date
gedmo:
timestampable:
on: create
updatedAt:
name: updated_at
type: date
gedmo:
timestampable:
on: update
deletedAt:
name: deleted_at
type: date
nullable: true
我的模特:
class Example
{
private $id;
...
private $createdAt;
private $updatedAt;
private $deletedAt;
public function getId()
{
return $this->id;
}
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
public function getCreatedAt()
{
return $this->createdAt;
}
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getUpdatedAt()
{
return $this->updatedAt;
}
public function setDeletedAt($deletedAt)
{
$this->deletedAt = $deletedAt;
return $this;
}
public function getDeletedAt()
{
return $this->deletedAt;
}
}
在控制器中,例如,要通过其ID获取文档,我有:
/**
* Get a single entity.
*
* @ApiDoc(
* resource=true,
* description="Get a single Example.",
* output= {"class"=Example::class},
* statusCodes={
* 200="Returned when successful",
* 404="Returned when not found"
* },
* parameters={
* {"name"="id", "dataType"="integer", "required"=true, "description"="Example id"}
* }
* )
*
* @FOS\Get("/example/{id}", requirements={"id": "([a-f\d]{24})|(\d+)"})
* @FOS\View
*
* @param Example $example
*
* @return Response
*/
public function getExampleAction(Example $example)
{
return array('example' => $example);
}
请问,我做错了什么?
我已经有2天时间尝试不同的事情,但没有:(
答案 0 :(得分:0)
在文档中说: “目前,它仅适用于ORM”
https://github.com/stof/DoctrineExtensions/blob/master/doc/softdeleteable.md
所以我认为它不适用于ODM,对不起。 你能完成查询以检查deletedAt字段吗?