0

我有两个实体,联系人和全球。

Example\EventBundle\Entity\EventGlobal:
    type: entity
    table: EventGlobal
       fields:
          id:
              id: true
              type: integer
              generator:
                strategy: AUTO
  oneToOne:
      EventKontakt:
      targetEntity: Example\EventBundle\Entity\EventContact
      mappedBy: EventGlobal
      cascade: ["persist"]



Example\EventBundle\Entity\EventContact:
    type: entity
    table: EventContact
    fields:
      EventGlobal_id:
       id: true
       type: integer
      oneToOne:
        EventGlobal:
         targetEntity: Example\EventBundle\Entity\EventGlobal
         inversedBy: EventContact
         joinColumns:
           EventGlobal_id:
             referencedColumnName: id
             nullable: false

他们工作正常。现在我用 Symfony 构建一个表单

        public function buildForm(FormBuilder $builder, array $options)
{
    $builder
        ->add(Stuff..)
        ->add('EventContact', new EventContactType($this->options))
    ;
}

表单正确呈现,具有一对一的关系。但是当我保存时,我得到一个错误。

我的错误是:

    Entity of type Example\EventBundle\Entity\EventContact is missing an assigned ID. The identifier generation strategy for this entity requires the ID field to be populated before EntityManager#persist() is called. If you want automatically generated identifiers instead you need to adjust the metadata mapping accordingly. 

我怎样才能实现我的安全是由 Symfony/Doctrine 完成的?

4

1 回答 1

0

您需要为 EventContact 添加生成器。

为您的 EventContact 实体。

fields:
   EventGlobal_id:
   id: true
   type: integer
   generator:
       strategy: AUTO
于 2012-04-06T22:14:58.543 回答