2012-04-06 71 views
0

我有兩個實體,聯繫人和全局。學說實體缺少分配的ID

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. 

我怎樣才能achive我後的安全是由Symfony的/學說做了什麼?

回答

0

您需要爲EventContact添加生成器。

您的EventContact實體。

fields: 
    EventGlobal_id: 
    id: true 
    type: integer 
    generator: 
     strategy: AUTO 
+0

它的工作部分,如果我只產生一個eventglobal沒有eventcontact一次,然後返回生成這兩個ID是壞了,並鏈接到最後一個條目。 – Tny 2012-04-06 23:27:15