query

Hi, what would this query look like as per cake?

'SELECT COUNT( * )FROM orders`LEFT JOIN `product_details` AS `ProductDetail` ON ( `orders`.`product_detail_id` = `ProductDetail`.`id` )WHERE `ProductDetail`.`new_or_used` = "New" GROUP BY `orders`.`user_id');

I tried it as

$this->Order->find->('count',

array(

'group'=>array('Order.user_id')

'conditions'=>array('CarDetail.new_or_used'=>"New")

)

);

$this-set etc

but i get an incorrect result set.

Asked by jamesl, on 15/2/10

1 Answer

create the relation between orders and product details and that will do the


`LEFT JOIN `product_details` AS `ProductDetail` ON ( `orders`.`product_detail_id` = `ProductDetail`.`id` )

then u shoulld be able to do the find like


$this->Order->find->('all',
    array(
        'fields' => array(
            'Order.user_id',
            'COUNT(Order.id) AS count',
        )
        'group'=>array('Order.user_id')
    )
);

Answered by dogmatic69on 15/2/10

<< previous next >>

Your Answer

You can use Creole Wiki Syntax to format your text.

Tagged with

Rating

0

Viewed

166 times

Last Activity

on 15/2/10