0

Contact と Global の 2 つのエンティティがあります。

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))
    ;
}

フォームは、1 対 1 の関係で正しくレンダリングされます。しかし、保存するとエラーが発生します。

私のエラーは次のとおりです。

    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 に答える