0

下面显示的是我的 mysql 查询。它运行良好。但我需要在 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' 

请帮我..

4

2 回答 2

1

食谱解释了如何做到这一点: http: //book.cakephp.org/2.0/en/models/associations-linking-models-together.html#joining-tables

于 2013-09-25T12:12:45.533 回答
1
$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);
于 2013-09-25T12:16:33.387 回答