2
我有以下實體類別在YML中定義,具有雙向多對多關係。當我嘗試通過doctrine:fixtures:load
加載在相應的數據庫中的數據燈具我收到PDO異常錯誤1048約完整性違反了「名稱」字段不能爲空Doctrine2 PDO異常完整性違規1048 - 燈具加載 - YML
# 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) {
\t $this - > slug = $slug;
\t return $this;
}
/**
* Get slug
*
* @return string
*/
public
function getSlug() {
\t return $this - > slug;
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public
function setSlugValue() {
\t $sl = new Slugify();
\t $this - > slug = $sl - > slugify($this - > getName());
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public
function prePersist() {
\t $this - > slug = '';
}
我們可能會看到您的固定裝置(S)? – scoolnico
更新了與燈具鏈接的問題。 –