我有兩個實體:面試和評論。面試與評論有一對多的單向關係。學說2:無法正確設置一對多關係
這裏是我的評論YAML映射文件:
Entities\Comment:
type: entity
table: Comment
repositoryClass: Repositories\CommentRepository
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
parentid:
type: integer
nullable: false
column: parentid
isactive:
type: integer
nullable: false
column: isactive
isremoved:
type: integer
nullable: false
column: isremoved
removaldate:
type: datetime
nullable: true
column: removaldate
user_name:
type: string
length: 255
nullable: false
column: user_name
user_email:
type: string
length: 255
nullable: false
column: user_email
user_avatar:
type: string
length: 255
nullable: false
column: user_avatar
comment:
type: text
nullable: false
column: comment
creationdate:
type: datetime
nullable: false
column: creationdate
rating:
type: integer
nullable: false
這裏是我的YAML映射文件專訪:
Entities\Interview:
type: entity
table: Interview
repositoryClass: Repositories\InterviewRepository
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
isremoved:
type: integer
nullable: false
column: isremoved
removaldate:
type: datetime
nullable: true
column: removaldate
creationdate:
type: datetime
nullable: false
column: creationdate
rating:
type: integer
nullable: false
anonstitle:
type: string
length: 1000
nullable: false
column: anonstitle
anons:
type: text
nullable: false
column: anons
anonsphoto:
type: string
length: 255
nullable: true
column: anonsphoto
interviewtitle:
type: string
length: 1000
nullable: false
column: interviewtitle
interview:
type: text
nullable: true
column: interview
interviewphoto:
type: string
length: 255
nullable: true
column: interviewphoto
manyToMany:
comments:
targetEntity: Comment
joinTable:
name: interviews_comments
joinColumns:
interview_id:
referencedColumnName: id
inverseJoinColumns:
comment_id:
referencedColumnName: id
unique: true
所以加載架構數據庫後,我有3個表。其中2個是實體表,一個是關係,它只有2個列:interview_id,comment_id。但是在爲某些面試保留Comment對象之後,我沒有看到任何連接表。找不到原因。
無論您遇到問題,請張貼控制器代碼,更新或創建操作。 – Lighthart 2013-03-21 20:24:56