【发布时间】:2014-07-01 20:07:08
【问题描述】:
我将向您展示的架构中的每个实体都以这种方式定义:[ENTITY]。 每个实体都用“.idName”标识。 “.idName1.IdName2”等多个字段创建一个复合键,其中至少其中一个是外键。
[Device.deviceId] has [Bookable.deviceId.bookableId]
(.deviceId is a identifies a device)
[Bookable.deviceId.bookableId] has [Booking.deviceId.bookableId.bookingId]
(the tuple .deviceId.bookableId identifies a Bookable)
我已经实现了在 [Device] 和 [Bookable] 之间创建 oneToMany 关系(请参阅代码),但是当我想在 Bookable 和 Booking 之间建立另一个 oneToMany 关系时,它不起作用并且 Doctrine 给了我一个错误。运行后:
php app/console doctrine:schema:update
显示此错误:
[Doctrine\ORM\ORMException]
Column name `deviceId` referenced for relation from SearchDevice\WebBundle\Entity\Booking towards SearchDev
ice\WebBundle\Entity\Bookable does not exist.
完整的 yaml 代码是下一个: Device.orm.yml 文件:
SearchDevice\WebBundle\Entity\Device:
type: entity
id:
deviceId:
type: integer
generator: {strategy: AUTO}
oneToMany:
bookables:
targetEntity: Bookable
mappedBy: device
可预订文件:
SearchDevice\WebBundle\Entity\Bookable:
type: entity
id:
deviceId:
associationKey: deviceId
bookableId:
type: integer
generator: {strategy: AUTO}
manyToOne:
device:
targetEntity: Device
inversedBy: bookables
joinColumns:
deviceId:
referencedColumnName: deviceId
oneToMany:
bookings:
targetEntity: Booking
mappedBy: bookable
预订文件:
SearchDevice\WebBundle\Entity\Booking:
type: entity
id:
deviceId:
associationKey: deviceId
bookableId:
associationKey: bookableId
bookingId:
type: integer
generator: {strategy: AUTO}
manyToOne:
bookable:
targetEntity: Bookable
inversedBy: bookings
joinColumns:
deviceId:
referencedColumnName: deviceId
bookableId:
referencedColumnName: bookableId
看起来问题出在预订实体中,我说“deviceId”是可预订实体的列。由于它是外键列而不是显式列,因此 Doctrine 在处理这种关系时存在问题。
【问题讨论】:
标签: php symfony doctrine-orm doctrine yaml