Hello I have a PostgreSQL query that I would like to write using cakePHP format
SELECT
id,
title,
author,
postdate,
postcontent,
userID
FROM posts
WHERE
userID = 12
AND id IN (SELECT articleID FROM favourites WHERE articlesUserID = 12)
ORDER BY postdate DESC;
this is the format my query has right now in cakePHP :
$favouritearticles = $this->Favourite->query('SELECT id, title, author, postdate, postdatecreation, posteditdate, postcontent, "userID" FROM posts WHERE "userID" = '.$userID.'AND id IN (SELECT lngblogarticleid FROM favourites WHERE lngloginuserid = '.$userID.') ORDER BY postdate DESC');
It's working but if echo json_encode the result like this :
echo json_encode($favouritearticles);
I get an invalid json format like the following :(checked with JSONLint)
[
[
{
"id": 2,
"title": "Prison Or Treatment For the Mentally ill ",
"author": "mike123",
"postdate": "March 12, 2013 at 6:46 pm",
"postdatecreation": "2013-03-12",
"posteditdate": null,
"postcontent": "<p><span>The public revulsion over repeated mass shootings has placed mental health in the spotlight. This is both good and bad.<\/span><\/p>",
"userID": 34
}
]
][
]
So I thought that maybe I should rewrite my query using cakePHP format "using find method" something like :
$favouritearticles = $this->Favourite->find('all',array('conditions'=>array(".........
however the query is quite complex and I don't see how to do so. Thank you for any help.