我有两个链接在一起的对象:
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没有被创建...
答案 0 :(得分:6)
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