views:

178

answers:

2

I got app that need to be recoded in CakePHP.

I got following select with subselects:

        SELECT COUNT(*) AS item1,
            (SELECT COUNT(*) FROM portal_members) AS item3, 
            (SELECT COUNT(*) FROM portal_reviews) AS item3, 
            (SELECT COUNT(*) FROM portal_downloads) AS item4
        FROM portal_articles 
        WHERE 1 = 1

Anyone have any idea how to create that query using CakePHP find($type, $params) ?

A: 

The CakePHP cookbook contains some subquery examples here:

http://book.cakephp.org/view/74/Complex-Find-Conditions

kg
Yeah, found them, but cannot apply them to my sub-selects
Johannes
+1  A: 

If that is your exact query, I'd recommend doing it in four passes.

$item1 = $this->PortalArticle->find('count');
$item2 = $this->PortalReview->find('count'); // etc..

It might take a wee bit longer to run, but your intentions are much clearer and the code would be much cleaner.

nickf
This is the way I did it first time, but thought there might by more strict method. Thanks for reply. Will do this that way!
Johannes