4

我有以下 Doctrine 2 STI Vehicle 实体,它有两个名为 Car 和 Bike 的子类,需要按车辆类型计算车辆表中的项目。(例如;表格摘要:3 辆汽车,5 辆自行车..)

/**
 * @ORM\Entity
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @ORM\DiscriminatorMap({"V" = "Vehicle", "C" = "CarEntity", "B" = "BikeEntity"})
 * @ORM\Table(name="vehicles", uniqueConstraints={@ORM\UniqueConstraint(name="discr_type_name",columns={"type","name"})})
 */
class Vehicle {
...
}

因此,我尝试了以下 DQL 查询,但没有一个有效:

SELECT v, TYPE(v) as vtype, count(v.id) as cnt FROM Vehicle v GROUP BY TYPE(v);
SELECT v, count(v.id) as cnt, TYPE(v) as vtype FROM Vehicle v GROUP BY vtype;
SELECT v, count(v.id) as cnt, TYPE(v) as vtype FROM Vehicle v GROUP BY TYPE(vtype);

查询异常:

[Syntax Error] line 0, col 10: Error: Expected known function, got 'TYPE'

另一个:

[Semantical Error] line 0, col 83 near 'TYPE()': Error: Cannot group by undefined identification or result variable

有任何想法吗?(学说版本是 2.3)

4

0 回答 0