[symfony-users] Re: How to convert a SQL query to a Doctrine left join with subquery

2010-05-16 Thread El Duderino
That's working perfectly now using the HYDRATE_RECORD and looping - I only had to change the query to group by r.id so it shows all requests with or without a comment made. Very much appreciated. On May 13, 5:02 pm, grahamj42 wrote: > $collection is a Doctrine_Collection object. This has a metho

[symfony-users] Re: How to convert a SQL query to a Doctrine left join with subquery

2010-05-13 Thread grahamj42
$collection is a Doctrine_Collection object. This has a method get() which can take a row number and returns a Doctrine_Record object. The Doctrine-Record object can be accessed by field name, so $collection->get(0)->title should return the title of the first request. Alternatively, you can use H

[symfony-users] Re: How to convert a SQL query to a Doctrine left join with subquery

2010-05-13 Thread El Duderino
The simplified DQL looks good and returns the correct rows including the last created_at so definite progress. You mentioned using $collection=$q- >execute(array(),Doctrine_Core::HYDRATE_RECORD); // to retrieve all the records How exactly would I be able to use this to pull the comment's last dat

[symfony-users] Re: How to convert a SQL query to a Doctrine left join with subquery

2010-05-13 Thread grahamj42
I would start by simplifying the query: SELECT r.*, MAX(c.created_at) AS last_comment FROM request r LEFT JOIN comment c on r.id=c.request_id GROUP BY c.request_id; This can be expressed using DQL as: $q=Doctrine_Query::create()->select( 'r.*, MAX(c.created_at) AS last_comment' )->from( 'req