const cloudbase = require('@cloudbase/node-sdk');
const cloud = require('wx-server-sdk');
const app = cloudbase.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
const models = app.models;
exports.main = async (event, context) => {
let ids = event.data.types
let orConditions = null
let code = event.data.areaCode
if (typeof code === 'string') {
code = parseInt(code)
}
if (ids.indexOf('-1') == -1 && ids.length) {
orConditions = ids
}
const {
data
} = await models.farmwork_order.list({
filter: {
relateWhere: {
farmland_id: {
where: {
$and: [{
district_code: {
$eq: code
}
}]
}
},
...(orConditions && {
tasktype_id: {
where: {
_id: {
$in: orConditions
}
}
}
})
},
where: {
$and: [{
order_status: {
$eq: 0
}
}],
}
},
orderBy: [{
createdAt: "desc", // 创建时间,倒序
}, ],
select: {
_id: true,
notes: true,
order_status: true,
start_date: true,
medias: true,
publish_date: true,
receive_date: true,
complete_date: true,
farmland_id: {
_id: true,
address: true,
area_text: true,
district_code: true,
city_code: true,
province_code: true,
crops: true
},
tasktype_id: {
_id: true,
name: true
}
},
pageSize: event?.data?.pageSize ?? 50,
pageNumber: event?.data?.pageNumber ?? 1,
getCount: true
})
return data;
};
上面就是查询代码,farmland_id跟tasktype_id 都是关联数据,当relateWhere中加入farmland_id相关的查询后,返回的列表数据中就没有farmland_id的数据,加入tasktype_id的条件后,返回的数据就缺少tasktype_id的数据。去掉relateWhere的筛选条件后,返回的数据,就包含有farmland_id、tasktype_id的关联数据。请问一下这个什么情况?