Doctrine orm 教义2-关系

Doctrine orm 教义2-关系,doctrine-orm,yaml,Doctrine Orm,Yaml,我正在开发一个应用程序,它正在寻找公共交通的最佳路线和时间表。我对Doctrine1有一些经验,但这是我第一次接触Doctrine2。有许多新的字段来描述关系(mappedBy和inversedBy),也有一些新的映射方式 我有以下代码: $query = $this->em->createQuery("SELECT partial cls.{stop}, partial t.{arriveTime, departureTime} FROM \Entities\Timetable t

我正在开发一个应用程序,它正在寻找公共交通的最佳路线和时间表。我对Doctrine1有一些经验,但这是我第一次接触Doctrine2。有许多新的字段来描述关系(mappedBy和inversedBy),也有一些新的映射方式

我有以下代码:

$query = $this->em->createQuery("SELECT partial cls.{stop}, partial t.{arriveTime, departureTime} FROM \Entities\Timetable t 
JOIN t.ride r
JOIN t.carrierLineStop cls
WHERE t.departureTime>=:time AND 
r.idCarrierLine=:carrierLine AND 
(cls.idStop=:firstStop OR cls.idStop=:lastStop)");
$query->setParameters(array(
    'time' => $time,
    'carrierLine' => $path->getLine(),
    'firstStop' => $path->getFirstStop(),
    'lastStop' => $path->getLastStop()
));
当我尝试执行该脚本时,出现了一个错误:

[Semantical Error] line 0, col 24 near '}, partial t.{arriveTime,': Error: There is no mapped field named 'stop' on class Entities\CarrierLineStop.
映射文件:

Entities\CarrierLineStop:
type: entity
table: carrier_line_stop
fields:
    idCarrierLineStop:
        id: true
        type: integer
        unsigned: false
        nullable: false
        column: id_carrier_line_stop
        generator:
            strategy: IDENTITY
    nextStop:
        type: integer
        unsigned: false
        nullable: true
        column: next_stop
manyToOne:
    idCarrierLine:
        targetEntity: Entities\CarrierLine
        cascade: {  }
        mappedBy: null
        inversedBy: null
        joinColumns:
            id_carrier_line:
                referencedColumnName: id_carrier_line
        orphanRemoval: false
    stop:
        column: id_stop
        targetEntity: Entities\Stop
        cascade: {  }
        mappedBy: null
        inversedBy: carrierLineStop
        joinColumns:
            id_stop:
                referencedColumnName: id_stop
        orphanRemoval: false
lifecycleCallbacks: {  }
-


我不知道问题出在哪里…

我认为关键字partial只适用于实体字段(如idCarrierLineStop和nextStop),stop是一个复合字段


如果你想像这样离开查询,你应该删除manytone映射,添加一个id_stop的字段映射,或者在查询中添加一个与stop实体的连接,并返回它的id来代替cls。{stop}

最后,我在Doctrine核心类中做了一些小的修改,解决了这个问题-我已经创建了一个类(不记得是哪一个)把关系也读作映射字段。我知道这不是一个简单的解决方案,但我没有别的办法让它工作
Entities\Stop:
type: entity
table: stop
fields:
    idStop:
        id: true
        type: integer
        unsigned: false
        nullable: false
        column: id_stop
        generator:
            strategy: IDENTITY
    name:
        type: string
        length: 45
        fixed: false
        nullable: true
    miejscowosc:
        type: string
        length: 45
        fixed: false
        nullable: true
    latitude:
        type: decimal
        nullable: true
    longitude:
        type: decimal
        nullable: true
oneToMany:
    carrierLineStop:
        targetEntity: Entities\CarrierLineStop
        cascade: {  }
        mappedBy: stop
        inversedBy: null
        joinColumns:
            id_stop:
                referencedColumnName: id_stop
        orphanRemoval: false
lifecycleCallbacks: {  }