Doctrine 2 DQL:如何通过鉴别器列(STI)进行分组

时间:2013-08-24 18:34:18

标签: orm doctrine-orm dql

我有以下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);

QueryException:

[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)

0 个答案:

没有答案