【问题标题】:Doctrine YML mapping referencesDoctrine YML 映射参考
【发布时间】: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


    【解决方案1】:

    在 ProducerTranslation $ProducerTranslation->setProducer($Producer) 中存储集 Producer 之前
    为什么您允许 ProducerTranslation.id_producer 为空?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-23
      • 1970-01-01
      • 2011-04-17
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多