Eti*_*oël 1 php orm yaml symfony doctrine-orm
我有两个链接在一起的对象:
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: { }
Run Code Online (Sandbox Code Playgroud)
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: { }
Run Code Online (Sandbox Code Playgroud)
我有以下错误,我一直在敲打我的头,没有任何线索:
[Mapping] FAIL - 实体类'OSC\UserBundle\Entity\Child'映射无效:
关联OSC\UserBundle\Entity\Child#parent指的是不存在的反面字段OSC\UserBundle\Entity\User#children.
事情就是定义了!
我也注意到使用命令doctrine:generate:entities OSC,我的属性children没有创建...
找到了 !我不是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
Run Code Online (Sandbox Code Playgroud)