CakePHP は初めてで、テーブル全体のリレーションの概念は非常に混乱しています。
コンピテンシーとコンピテンス評価の 2 つのテーブルがあります。コンピテンシーは、名前と ID のリストを格納します。
competencies
------------
id
name
ユーザーは、このテーブルからさまざまなコンピテンシーを選択して評価できます。その評価は、competenceRatings テーブルに格納されます。
competenceRatings
-----------------
id
competence_id
user_id
rating
ユーザーが評価を行っていないコンピテンシーの名前を、competenceRatings テーブルに取得できるようにしたいと考えています。つまり、comptenceRatings テーブルに (指定された user_id に対して) エントリがないコンピテンシー テーブルからの名前のリストが必要です。
コンピテンシー->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 );