教义2 - 关系



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

我有以下代码:

$query = $this->em->createQuery("SELECT partial cls.{stop}, partial t.{arriveTime, departureTime} FROM EntitiesTimetable 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 EntitiesCarrierLineStop.

映射文件:

EntitiesCarrierLineStop:
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: EntitiesCarrierLine
        cascade: {  }
        mappedBy: null
        inversedBy: null
        joinColumns:
            id_carrier_line:
                referencedColumnName: id_carrier_line
        orphanRemoval: false
    stop:
        column: id_stop
        targetEntity: EntitiesStop
        cascade: {  }
        mappedBy: null
        inversedBy: carrierLineStop
        joinColumns:
            id_stop:
                referencedColumnName: id_stop
        orphanRemoval: false
lifecycleCallbacks: {  }

-

EntitiesStop:
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: EntitiesCarrierLineStop
        cascade: {  }
        mappedBy: stop
        inversedBy: null
        joinColumns:
            id_stop:
                referencedColumnName: id_stop
        orphanRemoval: false
lifecycleCallbacks: {  }

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

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

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

相关内容

  • 没有找到相关文章