下面显示的是我的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'
请帮帮我..
答案 0 :(得分:1)
食谱说明了如何执行此操作:http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#joining-tables
答案 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);