2012-11-01 77 views
2

我使用Symfony2與教條,除了一個多對一/一對多的自引用關係外沒有關係問題。Doctrine2多對一自我引用:父母不生成

我有一個實體客戶可以有零個,一個或多個實體(也是客戶)。當我使用'doctrine:generate:entities BundleName'生成實體時,我的Entity Customer.php中只有一個var'$ entities',並且沒有var'$ mother_house'。此外,生成的遷移(使用doctrine:migrations:diff)不包含創建新字段'mother_house_id'。

在Customer.orm.yml的模式是這樣的一個:

Acme\Bundle\CustomerBundle\Entity\Customer: 
    type: entity 
    table: customer 
    repositoryClass: Acme\Bundle\CustomerBundle\Entity\CustomerRepository 
    fields: 
     id: 
      type: integer 
      id: true 
      generator: 
       strategy: AUTO 
     company_name: 
      type: string 
      length: 255 
     reference: 
      type: string 
      length: '20' 
     created_at: 
      type: datetime 

    oneToMany: 
     entities: 
      targetEntity: Customer 
      mappedBy: mother_house 

    manyToOne: 
     mother_house: 
      targetEntity: Customer 
      inversedBy: entities 
      joinColumn: 
       mother_house_id: 
        referencedColumnName: id 

    manyToOne: 
     created_by: 
      targetEntity: Acme\Bundle\UserBundle\Entity\User 
      joinColumn: 
       created_by: 
        referencedColumnName: id 
    lifecycleCallbacks: { } 

回答

1

我發現我的錯誤。

相同類型的所有關係(多對一一對一,一對多等)必須在一個場「多對一」進行分組,「一對多」等

所以我只是有改變

manyToOne: 
    mother_house: 
     targetEntity: Customer 
     inversedBy: entities 
     joinColumn: 
      mother_house_id: 
       referencedColumnName: id 

manyToOne: 
    created_by: 
     targetEntity: Acme\Bundle\UserBundle\Entity\User 
     joinColumn: 
      created_by: 
       referencedColumnName: id 

manyToOne: 
    mother_house: 
     targetEntity: Customer 
     inversedBy: entities 
     joinColumn: 
      mother_house_id: 
       referencedColumnName: id 
    created_by: 
     targetEntity: Acme\Bundle\UserBundle\Entity\User 
      joinColumn: 
      created_by: 
       referencedColumnName: id