0
votes

Each entity in the schema that I am going to show you is defined in this way: [ENTITY]. Every entity is identified with ".idName". Several fields like ".idName1.IdName2" create a compound key, where at least one of them is a foreign key.

[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)

I already achieved to create a oneToMany relation between [Device] and [Bookable] (see code) however when I want to make another oneToMany relation between Bookable and Booking it does not work and Doctrine gives me an error. After running:

php app/console doctrine:schema:update

Shows this error:

[Doctrine\ORM\ORMException]                                                                                  
Column name `deviceId` referenced for relation from SearchDevice\WebBundle\Entity\Booking towards SearchDev  
ice\WebBundle\Entity\Bookable does not exist.   

The full yaml code is the next one: Device.orm.yml file:

SearchDevice\WebBundle\Entity\Device:
    type: entity
    id:
        deviceId:
            type: integer
            generator: {strategy: AUTO}
    oneToMany:
        bookables:
            targetEntity: Bookable
            mappedBy: device

Bookable file:

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

Booking file:

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

Looks like if the problem is in Booking entity, where I am saying that "deviceId" is a column of Bookable entity. Since it is a foreign key column and not an explicit column then Doctrine has problems doing this relationship.

1

1 Answers

0
votes

Why don't you only use bookableId for your manyToOne relation ? bookableId haves an auto-increment id so it is obviously unique. Maybe a simply joinColumns on

bookableId:
                referencedColumnName: bookableId

Could be efficient in your Booking entity.

I am not sure because I am usually using annotations. But I don't udnerstand why you have to join on devideId to join on bookings if bookableId is unique.