在 Bookshelf.js 中,如何在 .where() 中实现一些条件逻辑?
其次,如何正确地将查询变量传递给它?
鉴于...
.query('location')
.model.query(qb => {
qb.join('locations', 'events.Location', 'locations.id')
.where(
// some logic here, like:
myFunction(
{ latitude: Latitude, longitude: Longitude },
{ latitude: ctx.query.Latitude, longitude: ctx.query.Longitude }
) >= 5000
)
})
.fetch();
... 抛出一个错误,如:ReferenceError: Latitude is not defined
。
仅供参考,纬度和经度存在于“位置”中。