Doctrine2 - 关系

时间:2012-11-23 16:53:48

标签: doctrine-orm yaml

我正在开发一个应用程序,它正在寻找公共交通的最佳路线和时间表。我对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: {  }

-

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

我不知道问题出在哪里......

1 个答案:

答案 0 :(得分:0)

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

如果要保留这样的查询,则应删除ManyToOne映射并使用id_stop添加字段映射,或者在查询中添加带有Stop实体的JOIN,并返回其id代替cls。{stop} < / p>