Product Plan ProductPlan
id |name id |name id | product_id | plan_id
1 aplha 1 a 1 1 2
2 bravo 2 b
3 charlie
我想根据 ProductPlan 查找产品名称和计划名称,如果 ProductPlan 中存在产品的产品 ID 和计划 ID,那么将显示计划和产品的名称,我尝试了很多,关系 b/w 表是正确的,但我没有t得到确切的数据,我使用的查询是
$p_plan = $this->ProductPlan->find('all',array(
'conditions'=>array(
'ProductPlan.product_id'=>'Product.product_id'
)
)
);
$this->set('p_plan', $p_plan);
如果有人帮助我,我会非常感谢他。提前致谢。
计划关系
class Plan extends AppModel{
public $primaryKey='plan_id';
public $hasMany = array(
'ProductPlan'=>array(
'className' => 'ProductPlan',
'foreignKey' => 'plan_id'
)
);
产品
class Product extends AppModel{
public $primaryKey='product_id';
public $hasMany = array(
'ProductsUser'=>array(
'className' => 'ProductsUser',
'foreignKey' => 'product_id'
),
'ProductsUserNode'=>array(
'className' => 'ProductsUserNode',
'foreignKey' => 'product_id'
),
'ProductPlan'=>array(
'className' => 'ProductPlan',
'foreignKey' => 'product_id'
)
);
产品计划
class ProductPlan extends AppModel{
var $primaryKey='product_plan_id';
public $belongsTo = array(
'Product' => array(
'className' => 'Product',
'foreignKey' => 'product_id'
),
'Plan' => array(
'className' => 'Plan',
'foreignKey' => 'plan_id'
)
);
public $hasMany = array(
'ProductPlansUserNode'=>array(
'className' => 'ProductPlansUserNode',
'foreignKey' => 'product_plan_id'
),
);
}