1

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

孩子.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: {  }

用户.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: {  }

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

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

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

问题是它被定义了!

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

4

1 回答 1

6

找到了 !我不是 100% 确定,但似乎你不能声明两次 manyToOne,这似乎是合乎逻辑的。删除它并将所有内容都放在一个块中,解决了我的问题!:

用户.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
于 2013-05-30T19:21:45.453 回答