When writing your queries, follow the CakePHP naming conventions - this makes the returned data much easier to handle.
SELECT * FROM `posts` as Post, `comments` as `Comment` ...
Then you get data returned that looks very similar to what you would get from a find()
, i.e. $queryResults['ModelName']['FieldName]
or $queryResults[0]['ModelName']['FieldName]
.
This link might help too. It relates to use of find
rather than query
, but it shows how you can create a method in your AppModel
to automatically reformat returned data (moving computed data into a model, to avoid having returned values at [0][0]).
http://teknoid.wordpress.com/2008/09/29/dealing-with-calculated-fields-in-cakephps-find/