I need to perform sql query using doctrine. query is really simple
SELECT q.*, COUNT(a.question_id) FROM question AS q LEFT JOIN question_answers AS a ON q.id=a.question_id GROUP BY a.question_id
For this purpose i wrote following code
$query = Doctrine_Query::create()
->select('q.*, COUNT(a.question_id) AS answers')
->from('Model_Question q')
->leftJoin('Model_QuestionAnswers a ON q.id = a.question_id')
->groupBy('a.question_id');
But this is not getting me desired query. Can anybody explain me what I am missing? Query that is generated I checked via $query->buildSqlQuery() is
SELECT q.id AS q__id, q.title AS q__title, q.short_description AS q__short_description,
q.created_at AS q__created_at, q.updated_at AS q__updated_at, q.is_visible AS
q__is_visible, q.category_id AS q__category_id, q.user_id AS q__user_id, q.category_name
AS q__category_name, q.username AS q__username, COUNT(q2.question_id) AS q2__0 FROM
question q, question_answers q2 GROUP BY q2.question_id
ONcondition from the join (this should be the default condition judging from your model so there is no reason to specify it - it will be joined on these columns automatically)? - prodigitalson