cakephp在一个联接表中一次联接两个以上的表 [英] cakephp join more than 2 tables at once in one join table

查看:108
本文介绍了cakephp在一个联接表中一次联接两个以上的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地将我的许多项目转换为Cake,但是我面临着一个我正在努力克服的挑战.

I have converted many of my projects across to Cake with success, but I have one that poses a challenge that I am struggling with.

在典型的"hasMany through"连接中,例如.在Cake文档中,您有3个表,分别为StudentCourseCourseMembership. StudentCourse hasMany CourseMembershipCourseMembership belongsTo StudentCourse.

In a typical "hasMany through" join, eg. in the Cake docs, you have 3 tables, Student, Course and CourseMembership. Student and Course hasMany CourseMembership and CourseMembership belongsTo Student and Course.

我的问题是,是否可以使用常规约定以这种方式将两个以上的表连接在一起?例如,添加另一个表,例如Lecturer(忘记现实的可能性)会创建更多可能的排列,但是Cake可以本地处理吗?

My question is, is it possible, using normal convention, to join more than two tables together in this way? For example, adding another table, say, Lecturer (forget the real world possibilities of this) would create more possible permutations but can Cake handle this natively?

谢谢.

这将是联接(HTH)的表布局:

here would be the table layout for the join (HTH):

id | student_id | course_id | lecturer_id

EDIT 2:默认情况下,联接表将被称为course_students,所以我需要的是具有上述布局的名为course_lecturer_students的表(显然,不需要调用它,而只是为了遵守CakePHP命名约定).

EDIT 2: by default, the join table would be called course_students so what I am after is a table called course_lecturer_students with the above layout (obviously it doesn't need to be called that but just to comply with CakePHP naming convention).

推荐答案

您可以将Cakephp用于

You could use Cakephp for

  1. 将简单的sql编写为查询(不可推荐)
  2. 写连接句
  3. 使用深层关联(可推荐)

但是您的问题尚不清楚,无法确定您要寻找的答案,或者您要寻找的答案

However you question is not clear and is not possible to determinate which kind of answer you are looking for, or what are you looking for

可能可以扩展您所寻找的最终结果,以帮助您

Probably you could extends with a final result of what you are looking for in order to help you

这篇关于cakephp在一个联接表中一次联接两个以上的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆