cakePHP表联接两个表的问题

编程入门 行业动态 更新时间:2024-10-28 21:24:59
本文介绍了cakePHP表联接两个表的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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表联接两个表的问题

本文发布于:2023-10-19 19:03:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508474.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   cakePHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!