cakePHP是我的新手,整个表的关系概念非常令人困惑!
Im new to cakePHP and the whole table relations concept is very confusing!
我有2个表,能力和权限。能力存储具有ID的名称列表。
I have 2 tables, competencies and competenceRatings. competencies stores a list of names with ids.
competencies ------------ id name用户可以从此表中选择各种能力并对它们进行评分,并将他们的评分存储到competenceRatings表中
And users can select various competencies from this table and rate them and their ratings are stored into competenceRatings table.
competenceRatings ----------------- id competence_id user_id rating我想成为能够获取用户尚未对能力等级表进行任何评分的能力的名称。即,我需要从competencyRatings表中没有任何条目的表(对于给定的user_id)。
I want to be able to get the names of competencies for which a user have NOT made any ratings into competenceRatings table. i.e., I need list of names from competencies table for which there are no entries in comptenceRatings table(for given user_id).
我尝试了功能-> hasMany-> competenceRatings,
I tried competencies->hasMany->competenceRatings, competenceRatings->belongsTo->competencies relations.
$competencies = $this->Competence->CompetenceRating->find('all',array('CompetenceRating.user_id' => $userId,'CompetenceRatingpetence_id !=' => 'Competence.id'));但是没有用!
这样做结果需要其他关系吗?还是可以在查找查询中使用联接条件联接表?
Does this result require any other relations? Or can i just join tables using joins condition in find query?
谢谢。
编辑
此方法有效:
$options['joins'] = array( array( 'table' => 'competence_ratings', 'alias' => 'CompetenceRating', 'type' => 'LEFT OUTER', 'conditions' => array( 'Competence.id = CompetenceRatingpetence_id', 'CompetenceRating.user_id' => $userId ) ) ); $options['conditions'] = array( 'CompetenceRatingpetence_id'=> null );推荐答案
尝试一下
联接表
$data = $this->Competence->find('all', array('joins' => array( array( 'table' => 'competenceRatings', 'alias' => 'CompetenceRating', 'type' => 'inner', 'foreignKey' => false, 'conditions'=> array('CompetenceRatingpetencie_id = Competence.id') ), array( 'table' => 'competencies', 'alias' => 'Competence', 'type' => 'inner', 'foreignKey' => false, 'conditions'=> array( 'Competence.id = MarkersTag.tag_id', 'Competence.user_id' => $user_id ) ) )));更多推荐
cakePHP表联接两个表的问题
发布评论