Php YML映射参考
解析存储实体“producer”,该实体包括具有属于此实体的翻译的数组 成功保存数据库。但是,在包含翻译的表中,缺少到“producer”表的链接 这一结果: 我的制作人:Php YML映射参考,php,mysql,symfony,doctrine-orm,doctrine,Php,Mysql,Symfony,Doctrine Orm,Doctrine,解析存储实体“producer”,该实体包括具有属于此实体的翻译的数组 成功保存数据库。但是,在包含翻译的表中,缺少到“producer”表的链接 这一结果: 我的制作人: +----+----+ | id |code| +----+----+ | 1 |abcd| +----+----+ 我的制作人翻译 +----+-----------+----+------+ | id |id_producer|name|locale| +----+-----------+----+------+ |
+----+----+
| id |code|
+----+----+
| 1 |abcd|
+----+----+
我的制作人翻译
+----+-----------+----+------+
| id |id_producer|name|locale|
+----+-----------+----+------+
| 1 | NULL |abcd| en |
+----+-----------+----+------+
| 2 | NULL |abcd| de |
+----+-----------+----+------+
实体生成翻译
ProducerTranslation
{
protected $id;
protected $name;
protected $producer;
protected $locale;
... getters and setters
}
实体生产者
Producer
{
protected $id;
protected $code;
protected $translations;
public function __construct()
{
$this->translations = new ArrayCollection;
}
... getters and setters, method for adding translations (entity ProductTranslation)
}
生产者YML
My\ProducerBundle\Entity\Producer:
type: entity
table: my_producer
id:
id:
type: integer
generator:
strategy: AUTO
fields:
code:
type: string
length: 50
nullable: true
oneToMany:
translations:
targetEntity: ProducerTranslation
mappedBy: producer
cascade: ["persist", "remove"]
生产者翻译
My\ProducerBundle\Entity\ProducerTranslation:
type: entity
table: my_producer_translations
id:
id:
type: integer
generator:
strategy: AUTO
fields:
name:
type: string
length: 100
locale:
type: text
length: 2
manyToOne:
producer:
targetEntity: Producer
inversedBy: translations
joinColumn:
name: producer_id
referencedColumnName: id
onDelete: CASCADE
在ProducerTranslation中的存储集生产者之前
$ProducerTranslation->setProducer($Producer)
为什么ProducerTranslation.id\u producer允许空值