2012-11-23 92 views
0

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

我有下面的代码:

$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: { } 

-

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: { } 

我不知道有关的问题出在哪里?

回答

0

我认为,只有在实体领域(如idCarrierLineStop和nextStop)关键字部分作品,停止是复合场。

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

+0

终于我解决了这个问题,在Doctrine核心类的小修改 - 我做了一个类(不记得是哪个)也读取关系的映射字段。我知道这不是一个优雅的解决方案,但我没有其他想法使它成为可能 –