0

我想在我的查询中加入连接,但我无法获得任何成功,如果表中存在,我想productnameproduct表中找出。product_idproductplan

 Producttable     
 id name
  1   a
  2   b 

 productplantable
 id product_id
  1   1
  2   2

这是我的查询:

$p_products = $this->ProductPlan->find('all',   
                                       array('fields'=> 
                                         array('ProductPlan.product_id',
                                               'Product.name')
                                       )
                                    );
$this->set('p_products',$p_products);
4

1 回答 1

0

如果您的关系在您的 ProductPlan 模型中正确设置,则以下内容应该有效。如果没有,请提供您的 ProductPlan 模型的源代码。

$this->ProductPlan->Behaviors->attach('Containable');

$p_products = $this->ProductPlan->find('all', array(
  'fields'  => array('product_id'),
  'contain' => array('Product' => array('fields' => array('name')))  
));
$this->set('p_products',$p_products);
于 2013-03-22T16:24:42.623 回答