如何加入 3 个表并将所有三个表一起输出到 web2py 中? [英] How can I join 3 tables and output all three together joined in web2py?

查看:22
本文介绍了如何加入 3 个表并将所有三个表一起输出到 web2py 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

型号:

# coding: utf8
db.define_table('dept',
                Field('name',unique=True,label='Department Name'),
                format='%(name)s')

db.define_table('course',
                Field('dept_id','reference dept'),
                Field('name',unique=True,label='Course Name'),
            format='%(name)s')

db.define_table('files',
                Field('course_id', 'reference course'),
                Field('documentx','upload'))

控制器:

def show_doc():
    rows = db( db.course.id == db.files.course_id , db.dept.id==db.course.dept_id).select()
    return rows

我想要做的是将部门表dept"与course"表和course"表与files"表连接起来.因此,在输出时,它会显示一个包含课程和文件的部门的表格.该解决方案不起作用.它只会在课程"表和文件"表之间创建连接.

What I am trying to do is to join the department table "dept" with the "course" table and the "course" table with the "files" table. So when outputting it shows a table with department with course and files all together. The solution doesn't work. It only creates a join between the "course" table and the "files" table.

推荐答案

book,应该是:

db((db.course.id == db.files.course_id) & (db.dept.id==db.course.dept_id))

这篇关于如何加入 3 个表并将所有三个表一起输出到 web2py 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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