简体   繁体   中英

how to write inner join query in cakephp

below shown is my mysql query.it works well. but I need to do that in cakephp. how can I convert this into cake 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' 

please help me..

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM