Hello, I am having trouble converting this SQL query to a Cake query that
uses find():
SELECT Page.*, COUNT(*) AS views FROM
pages AS Page
INNER JOIN page_views AS PageView ON Page.id = PageView.page_id
GROUP BY Page.id
ORDER BY COUNT(*) DESC
LIMIT 10 OFFSET 0
This is what I've got, but it doesn't return anything:
$this->Page->find('all',
array(
'fields' => array('*', 'COUNT(*) as views'),
'conditions' => array('Page.id' => 'PageView.page_id'),
'group' => array('Page.id')
)
);
Can someone help me refine? Thank you.
--
View this message in context:
http://n2.nabble.com/Converting-SQL-query-to-Cake-query-tp2434189p2434189.html
Sent from the CakePHP mailing list archive at Nabble.com.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---