Symfony2 - 映射无效是指不存在的拥有方

时间:2013-05-29 17:05:58

标签: php symfony orm doctrine-orm yaml

我有两个链接在一起的对象:

Child.orm

OSC\UserBundle\Entity\Child:
    type: entity
    table: null
    repositoryClass: OSC\UserBundle\Entity\ChildRepository
    id:
        id:
            type: integer
            id: true
            generator:
                strategy: AUTO
    fields:
        firstName:
            type: string
            length: 255
        lastName:
            type: string
            length: 255
        dateOfBirth:
            type: datetime
            column: dateOfBirth
        isPlayer:
            type: boolean
            default: false
        isCoach:
            type: boolean
            default: false
    manyToOne:
        parent:
            targetEntity: User
            inversedBy: children


    lifecycleCallbacks: {  }

User.orm

OSC\UserBundle\Entity\User:
    type: entity
    table: null
    repositoryClass: OSC\UserBundle\Entity\UserRepository
    fields:
        id:
            type: integer
            id: true
            generator:
                strategy: AUTO
        lastName:
            type: string
            length: 255

        firstName:
            type: string
            length: 255

        streetNumber:
            type: string
            length: 255

        street:
            type: string
            length: 255

        province:
            type: string
            length: 255

        country:
            type: string
            length: 255

        homePhone:
            type: string
            length: 255

        mobilePhone:
            type: string
            length: 255
        isPlayer:
            type: boolean
            default: false
        isCoach:
            type: boolean
            default: false

        dateOfBirth:
            type: date
            column: dateOfBirth
    oneToMany:
        children:
            targetEntity: Child
            mappedBy: parent
    oneToMany:
        posts:
            targetEntity: OSC\BlogBundle\Entity\Post
            mappedBy: author

    lifecycleCallbacks: {  }

我有以下错误,我一直在敲打着我的头脑,没有任何线索:

[Mapping] FAIL - 实体类'OSC \ UserBundle \ Entity \ Child'映射无效:

关联 OSC \ UserBundle \ Entity \ Child#parent 指的是不存在的反面字段 OSC \ UserBundle \ Entity \ User#children

事情就是定义了!

我还注意到使用命令doctrine:generate:entities OSC,我的属性children没有被创建...

1 个答案:

答案 0 :(得分:6)

发现它!我不是100%肯定,但似乎你不能宣布两次很多ToOne,这似乎是逻辑。删除它并将所有内容放在一个块中就解决了我的问题!:

User.orm.yml

OSC\UserBundle\Entity\User:
    type: entity
    table: null
    repositoryClass: OSC\UserBundle\Entity\UserRepository
    fields:
        id:
            type: integer
            id: true
            generator:
                strategy: AUTO
        lastName:
            type: string
            length: 255

        firstName:
            type: string
            length: 255

        streetNumber:
            type: string
            length: 255

        street:
            type: string
            length: 255

        province:
            type: string
            length: 255

        country:
            type: string
            length: 255

        homePhone:
            type: string
            length: 255

        mobilePhone:
            type: string
            length: 255
        isPlayer:
            type: boolean
            default: false
        isCoach:
            type: boolean
            default: false

        dateOfBirth:
            type: date
            column: dateOfBirth

    oneToMany:
        children:
            targetEntity: OSC\UserBundle\Entity\Child
            mappedBy: parent
        posts:
            targetEntity: OSC\BlogBundle\Entity\Post
            mappedBy: author