user007
user007

Reputation: 61

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..

Upvotes: 0

Views: 3535

Answers (2)

Ayo Akinyemi
Ayo Akinyemi

Reputation: 777

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

Upvotes: 1

Related Questions