地点.yml
manyToOne:
excursions:
targetEntity: Excursions
inversedBy: places
inverse: true
cascade: ["ALL"]
nullable: false
joinColumn:
name: idx
referencedColumnName: place_id
游览.yml
oneToOne:
places:
targetEntity: Places
mappedBy: excursions
游览有一个 place_id。所以$exccursion->getPlaces()
只返回一行。
现在,当我尝试向Places
表中插入一个值时,Doctrine2 说Not null violation: 7 ERROR: null value in column "idx" violates not-null constraint
我不知道为什么会这样。如果我删除manyToOne
然后插入工作。但这一次getPlaces()
是行不通的。
更新
问题是,我对数据库使用 mappedBy。我应该只这样做:
地点.yml
manyToOne:
--remove--
游览.yml
oneToOne:
places:
targetEntity: Places
joinColumn:
name: place_id
referencedColumnName: idx
这解决了问题。但我通过随机尝试/播放发现了这一点。所以,我不知道为什么 :) 任何人都知道,请取悦explain
我。