解析商店实体" producer",其中包括具有属于该实体的翻译的数组。
保存数据库以成功。但是,在包含翻译的表中缺少指向" producer"。
表的链接结果:
my_producer:
+----+----+
| id |code|
+----+----+
| 1 |abcd|
+----+----+
my_producer_translations
+----+-----------+----+------+
| id |id_producer|name|locale|
+----+-----------+----+------+
| 1 | NULL |abcd| en |
+----+-----------+----+------+
| 2 | NULL |abcd| de |
+----+-----------+----+------+
Entity ProducerTranslation
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
答案 0 :(得分:2)
在ProducerTranslation $ProducerTranslation->setProducer($Producer)
中保存设置生产者之前
你为什么允许ProducerTranslation.id_producer的空值?