【发布时间】:2015-11-25 10:14:45
【问题描述】:
我在 YML 中定义了以下具有双向多对多关系的实体 Category。当我尝试通过doctrine:fixtures:load 将灯具数据加载到相应的数据库中时,我收到一个PDO Exception error 1048,关于“名称”字段不能为空的完整性违规
# src/tuto/JobeetBundle/Resources/config/doctrine/Category.orm.yml
tuto\JobeetBundle\Entity\Category:
type: entity
repositoryClass: tuto\JobeetBundle\Repository\CategoryRepository
table: category
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
length: 255
unique: true
slug:
type: string
length: 255
unique: true
oneToMany:
jobs:
targetEntity: Job
mappedBy: category
manyToMany:
affiliates:
targetEntity: Affiliate
mappedBy: categories
lifecycleCallbacks:
prePersist: [setSlugValue]
preUpdate: [setSlugValue]
/**
* @var string
*/
private $slug;
public
function setSlug($slug) {
$this - > slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public
function getSlug() {
return $this - > slug;
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public
function setSlugValue() {
$sl = new Slugify();
$this - > slug = $sl - > slugify($this - > getName());
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public
function prePersist() {
$this - > slug = '';
}
【问题讨论】:
-
我们可以看看你的灯具吗?
-
用夹具链接更新了问题。
标签: php symfony pdo doctrine-orm fixtures