【发布时间】:2015-04-22 13:12:32
【问题描述】:
我正在尝试使用gedmo/doctrine-extensions 的softdelete 选项,但由于某种原因,当我调用romove() 时,数据库中的记录被删除而不是更新deletedAt 字段。
在here,文档告诉我们更新配置:
$config->addFilter('软删除', 'Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter');
这只是我尝试的示例之一:
# app/config/config.yml
doctrine:
orm:
entity_managers:
default:
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true
参考文献(只是其中的几个):
- DoctrineExtensions SoftDeleteable
- http://knplabs.com/en/blog/gedmo-doctrine-extensions-on-symfony2
- Can't enable SoftDeleteable in Symfony2 - Unrecognized options "filters"
那么问题简单来说,在config.yml中怎么配置呢?
控制器
public function delete($id)
{
$profile = $this->profileRepository->findOneBy(['id' => $id]);
if (!$profile instanceof Profile) {
throw new ........
}
$this->entityManager->remove($profile);
$this->entityManager->flush();
return true;
}
实体
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity()
* @ORM\Table(name="profile")
* @Gedmo\SoftDeleteable(fieldName="deletedAt")
*/
class Profile
{
/**
* @ORM\Column(name="deletedAt", type="datetime", nullable=true)
*/
private $deletedAt;
......
}
COMPOSER.JSON
"require": {
"symfony/symfony": "2.6.*",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "~1.2",
"gedmo/doctrine-extensions": "2.3.*@dev",
......
},
CONFIG.YML
doctrine:
dbal:
default_connection: front
connections:
front:
driver: %database_driver%
host: %database_host%
........
back:
driver: %database_driver%
host: %database_host%
........
orm:
auto_generate_proxy_classes: %kernel.debug%
default_entity_manager: front
entity_managers:
front:
connection: front
mappings:
MyWebsiteBundle:
dir: Entity
FOSUserBundle: ~
back:
connection: back
地图信息:
inanzzz@inanzzz:/var/www/html/local$ php app/console doctrine:mapping:info
Found 8 mapped entities:
[OK] My\Bundle\Entity\AbstractMerchantProfile
[OK] My\Bundle\Entity\AbstractIntegration
[OK] My\Bundle\Entity\APIConsumer
[OK] My\Bundle\WebsiteBundle\Entity\User
[OK] My\Bundle\WebsiteBundle\Entity\Profile
[OK] My\Bundle\WebsiteBundle\Entity\Integration
[OK] FOS\UserBundle\Model\Group
[OK] FOS\UserBundle\Model\User
【问题讨论】:
标签: symfony doctrine-orm