I have quite a few problems rewriting a simple query using the methods provided by Propel 1.6.
The request is as follows:
SELECT type_id, COUNT(id) as `count` FROM visit GROUP BY type_id;
Using Propel, I wrote the following:
$visitCount = VisitQuery::create() ->withColumn('COUNT(id)', 'count') ->groupBy('TypeId') ->find();
This generates the following query:
SELECT visit.ID, visit.JOB_ID, visit.ENGINEER_ID, visit.TYPE_ID, visit.VISIT_DATE, visit.STATUS, COUNT(id) AS count FROM `visit` GROUP BY visit.TYPE_ID
Which works, but I only need the type_id and count columns , so I tried to add the following:
$visits = VisitQuery::create() ->withColumn('COUNT(id)', 'count') ->select(array('TypeId')) ->groupBy('TypeId') ->find();
This generates the following (working) request:
SELECT COUNT(id) AS count, visit.TYPE_ID AS "TypeId" FROM `visit` GROUP BY visit.TYPE_ID
However, I do not want to use the type_id column type_id . I tried passing the actual column name to the select array ( ->select(array('type_id')) ), however this leads to the following query (which obviously doesn't work):
SELECT COUNT(id) AS count, AS "type_id" FROM `visit` GROUP BY visit.TYPE_ID
How can I get a type_id column without its aliases?