cakephp属于自定义条件不起作用

时间:2014-10-13 21:08:03

标签: cakephp

// in Person
public $hasMany = array(
'PersonRecommendation' => array(
    'className' => 'PersonRecommendation',
    'foreignKey' => false,
    'dependent' => true,
),
)

// in PersonRecommendation
public $belongsTo = array(
'Person' => array(
    'className' => 'Person',
    'foreignKey' => false,
    'conditions' => array('Person.email = PersonRecommendation.email'),
),
);

当我用find()查询这些时,Person返回所有推荐。不只是通过电子邮件关联的那些我尝试了各种各样的事情,我很难过。有人可以帮忙吗?

使用蛋糕2.4.5。

2 个答案:

答案 0 :(得分:0)

您需要更改人物模型

public $hasMany = array(
   'PersonRecommendation' => array(
       'className' => 'PersonRecommendation',
       'foreignKey' => false,
       'dependent' => true,
       'conditions' => array('Person.email = PersonRecommendation.email')
    )
)

答案 1 :(得分:-1)

尝试以下方法:

'conditions' => array($Person->email => $PersonRecommendation->email)