【发布时间】:2015-12-20 11:38:25
【问题描述】:
解析存储实体“生产者”,其中包括具有属于该实体的翻译的数组。
保存数据库成功。但是,在包含翻译的表中缺少指向“生产者”表的链接。
这个结果:
我的制片人:
+----+----+
| id |code|
+----+----+
| 1 |abcd|
+----+----+
my_producer_translations
+----+-----------+----+------+
| 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"]
ProducerTranslation YML
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
【问题讨论】:
标签: php mysql symfony doctrine-orm doctrine