2013-09-25 60 views
0

下面顯示的是我的mysql query.it,效果很好。但我需要在cakephp中做到這一點。我怎麼能轉換到這個蛋糕的PHP如何在cakephp中寫入內連接查詢

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' 

請幫助我..

+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);