如何在cakephp中编写内连接查询

时间:2013-09-25 11:02:35

标签: mysql cakephp inner-join

下面显示的是我的mysql query.it运行良好。但我需要在cakephp中这样做。我该怎么把它转换成蛋糕php

SELECT pp.product_properties_id,ppv.product_property_value_id FROM product_properties pp 

INNER JOIN product_property_values  ppv ON pp.product_properties_id = ppv.properties_id

WHERE pp.property_name='Color' AND ppv.properties_value='Blue' 

请帮帮我..

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

$query_options = array();
$query_options['fields'] = array( 'pp.product_properties_id', 'ppv.product_property_value_id' );
$query_options['conditions'] = array( 'pp.property_name' => 'Color' , 'ppv.properties_value' => 'Blue');
$query_options['joins'] = array('table' => 'product_property_values',
                                    'alias' => 'ppv',
                                    'type' => 'INNER',
                                    'conditions' => array(
                                        'ppv.id = pp.ppv_id',
                                    )
                                );

$result = $this->pp->find('all', $query_options);