0
我新加入cakePHP和整个表关系的概念很混乱!cakePHP表加入两个表问题
我有2表,能力和competenceRatings。能力存储名称与ID的列表。
competencies
------------
id
name
而且,用户可以从该表中选择不同的能力和评价他们和他们的收视率被存储到competenceRatings表。
competenceRatings
-----------------
id
competence_id
user_id
rating
我希望能够获得用户没有对能力评分表进行任何评分的能力的名称。即,我需要能力表中没有条目的能力表中的名称列表(对于给定的user_id)。
我试图competencies-> hasMany-> competenceRatings,competenceRatings-> belongsTo->竞争力的关系。
$competencies = $this->Competence->CompetenceRating->find('all',array('CompetenceRating.user_id' => $userId,'CompetenceRating.competence_id !=' => 'Competence.id'));
但没用!
这个结果是否需要其他关系?或者我可以在查找查询中使用连接条件连接表吗?
谢谢。
编辑
此方法处理:
$options['joins'] = array(
array(
'table' => 'competence_ratings',
'alias' => 'CompetenceRating',
'type' => 'LEFT OUTER',
'conditions' => array(
'Competence.id = CompetenceRating.competence_id',
'CompetenceRating.user_id' => $userId
)
)
);
$options['conditions'] = array('CompetenceRating.competence_id'=> null);