左加入 web2py

Left Join web2py

我试过这个查询,但出现错误。 dtms_documents.dtype、'reference dtms_type'

这是我使用的查询:

    comms = db().select(db.dtms_documents.ALL, db.dtms_type.ALL, 
    left=db.dtms_type.on(db.dtms_documents.dtype==db.dtms_type.id))

https://ibb.co/rdv6ZkZ

当您进行联接并在 select 中包含来自两个 table 的字段时,要引用 row 对象中的给定字段值,您必须同时使用table 名称和字段名称(即 row.tablename.fieldname 而不仅仅是 row.fieldname)。所以,在你的字典中,而不是:

{'ref_no': comm.ref_no, ...}

应该是:

{'ref_no': comm.[tablename].ref_no, ...}

其中 [tablename] 可以是 dtms_documentsdtms_type,具体取决于 ref_no 字段属于哪个 table。