我在cakePHP中有两个表。CakePHP嵌套两个select查询
competencies
------------
id
name
competenceRatings
-----------------
id
competence_id
user_id
rating
我需要一种方法来写在蛋糕的方式下面的查询:
SELECT * FROM能力WHERE ID NOT IN(SELECT competence_id FROM competence_ratings WHERE雇员= $用户id)
有人请帮我!!
我做了什么,才去这个子查询方法:
我试图competencies-> hasMany-> competenceRatings,competenceRatings-> belongsTo->竞争力的关系。
$competencies = $this->Competence->CompetenceRating->find('all',array('CompetenceRating.user_id' => $userId,'CompetenceRating.competence_id !=' => 'Competence.id'));
我希望能够获得用户没有对能力评分表进行任何评分的能力的名称。即,我需要能力表中没有条目的能力表中的名称列表(对于给定的user_id)。
编辑
我试着表中还加入:
$options['joins'] = array(
array(
'table' => 'competence_ratings',
'alias' => 'CompetenceRating',
'type' => 'LEFT OUTER',
'conditions' => array(
'Competence.id = CompetenceRating.competence_id'
)
)
);
$options['conditions'] = array('CompetenceRating.employee_id' => $employee['Employee']['id']);
$competencies = $this->Competence->find('all',$options);
你到目前为止做了什么? – mark 2012-08-04 18:33:31
我正在谈论实际的代码。而不是只发布预期的结果,你也应该发布你到目前为止的代码。你可以编辑并完成你的问题。 – mark 2012-08-04 18:44:19
你再问同样的问题2或3小时你问“CakePHP表加入两个表问题”这个问题 – 2012-08-04 18:44:50