I am using web2py's DAL and trying to do the equivalent of this MySQL query.
SELECT header.tag, detail.site
FROM header
LEFT OUTER JOIN detail ON header.id= detail.header
WHERE header.tag IN ('abc', 'def', 'xyz')
I presumed that the DAL equivalent was as follows, but this code is giving me a cross product.
tags = ['abc', 'def', 'xyz']
query = (db.header.tag.belongs(tags) & db.header.id==db.detail.header)
raw_data = db(query).select(
db.header.tag,
db.detail.site,
)
SELECT header.tag, detail.site FROM header, detail;
If I omit the belongs
clause from my query, all works fine.
query = (db.header.id==db.detail.header)
raw_data = db(query).select(
db.header.tag,
db.detail.site,
)
SELECT header.tag, detail.site FROM header, detail WHERE (header.id = detail.header);
I am using this version: 2.12.3-stable+timestamp.2015.08.18.19.14.07