gpt4 book ai didi

php - Doctrine YML 映射引用

转载 作者:可可西里 更新时间:2023-11-01 08:26:58 25 4
gpt4 key购买 nike

解析商店实体“生产者”,其中包括带有属于该实体的翻译的数组。

保存数据库成功。但是,在包含翻译的表中缺少指向“生产者”表的链接。

这个结果:

我的制作人:

+----+----+
| 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

最佳答案

在 ProducerTranslation 中保存设置 Producer 之前 $ProducerTranslation->setProducer($Producer)
为什么允许 ProducerTranslation.id_producer 为 null?

关于php - Doctrine YML 映射引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34380601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com