Doctrine 2 DQL: as columns of a GROUP BY (STI) discriminator

I have an STI Vehicle Doctrine 2 STI training object that has two child classes, named Car and Bike, for counting items in vehicle tables by vehicle type. (For example, a summary of the table: 3 cars, 5 bicycles.)

/** * @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 { ... } 

So, I tried to execute DQL queries, but none of them worked:

 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' 

other:

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

Any ideas? (Doctrine Version 2.3)

+4
source share

Source: https://habr.com/ru/post/1498751/


All Articles