Help needed converting MySQL query to Doctrine Query-Collection of common programming errors

I’m trying to convert the following MySQL query which give me all clients who have not had an appointment for six months or more into a DQL query.

mysql> select appt.lastDate, clients.firstname, clients.lastname
-> from (select max(gapmtDate) as lastDate,gapmtClient from groomappointments group by gapmtClient) as appt ,clients
-> where date_sub(CURDATE(), INTERVAL 6 MONTH)>lastDate
-> AND clients.clientid = appt.gapmtClient;

I’ve tried to match this with the following but I receive an error stating that there is an unknown column g__0 in the where clause. Can anyone point out where I’m going wrong

public function noappointmentsforsixmonthsAction()
{



  $sixmonths=date('y-m-d',strtotime("-6 months"));

  $q=Doctrine_Query::create()
  ->select('MAX(g.gapmtDate) AS lastDate, c.firstname, c.lastname,g.gapmtClient')
 ->from('PetManager_Model_Groomappointments g')
 ->leftJoin('g.PetManager_Model_Clients c')
 ->where('lastDate

Originally posted 2013-11-09 23:28:18.