Hi, i recommend you to use DbFinderPlugin which is really useful with these
kinds of custom query.

On Sep 15, 2009 7:46 PM, "Zach" <[email protected]> wrote:


I have a raw sql query that selects all the columns in a table plus a
custom column (distance). I then use TablePeer::populateObjects() to
get my array of table objects.
This works fine, but I don't know how to get the custom column.

 function inradius($lat,$lon,$radius){
       $connection = Propel::getConnection();
       $query = 'SELECT *,
(3959*acos(cos(radians('.$lat.'))*cos(radians(%s))
*cos(radians(%s)-radians('.$lon.'))+sin(radians('.$lat.'))*sin(radians
(%s)))) AS distance FROM %s HAVING distance <'.$radius.'  ORDER BY
distance LIMIT 0 , 6;';
       $query = sprintf($query, TablePeer::LATITUDE, TablePeer::LONGITUDE,
TablePeer::LATITUDE, TablePeer::TABLE_NAME);
       $stmt = $connection->prepareStatement($query);
       $rs = $stmt->executeQuery($query, ResultSet::FETCHMODE_NUM);
       $tableobjects = TablePeer::populateObjects($rs);
       return $tableobjects;
   }

How can I also return the distance (the alias for the custom select
column) with the table objects? I suppose I could edit populateObjects
() but it would be no good once I rebuild the model. Or I could do an
extra query for each object to get the distance, but that seems
redundant when I already have all the data I need in this one query.
Any ideas would be greatly appreciated!

Thanks, Zach

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to