Doctrine2多对一自我引用:父母未产生



我正在使用Symfony2与学说使用,并且关系没有任何问题,除了一个多对一/一对一的自我引用关系。

我有一个实体客户,可以具有零,一个或多个实体(也是客户)。当我使用"学说:生成:bundlename"生成实体时,bundlename"我只有一个var'$ entities'在我的实体customer.php中,并且没有var'$ mother_house'。此外,生成的迁移(使用学说:迁移:diff)不包含创建一个新领域的" homet_house_id"。

customer.orm.ym中的架构是一个:

AcmeBundleCustomerBundleEntityCustomer:
    type: entity
    table: customer
    repositoryClass: AcmeBundleCustomerBundleEntityCustomerRepository
    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: AcmeBundleUserBundleEntityUser
            joinColumn: 
                created_by:
                     referencedColumnName: id
    lifecycleCallbacks: {  }

我发现了我的错误。

必须将同一类型的所有关系(多对一,一对多等)分组为一个字段"多人"," Onetomany"等。

所以我只需要更改

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

进入

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

相关内容

  • 没有找到相关文章

最新更新