javascript - ObjectionJS:将选择/列附加到当前查询
问题描述
我正在使用 Objection.js 模型修饰符来按地理位置限制某些查询,我不确定如何在不替换它们的情况下将列附加到当前查询。
例如,在地理半径内搜索配置文件时,最好使用查询返回距离:
static modifiers = {
withinMiles(query, profileId: string, miles: number = 100) {
query
.column({
distance: raw(
`earth_distance(
ll_to_earth(targetProfile.geo_lat, targetProfile.geo_lon),
ll_to_earth(person.geo_lat, person.geo_lon)
)`
),
})
.join('profile as targetProfile', 'profile.id', raw(`'${profileId}'`))
.whereRaw(
`earth_box(ll_to_earth(targetProfile.geo_lat, targetProfile.geo_lon), 100)
@> ll_to_earth(profile.geo_lat, profile.geo_lon)`
);
},
};
不幸的是,这将替换当前查询和任何图形连接中的列。
解决方案
推荐阅读
- variables - 从 netCDF 中的变量重写属性
- python - 是否可以使用 Spotipy 更改播放列表图像?
- java - 尝试使用 Java 更新 CSV 文件,但文件大小不断增加,尽管代码清空了其内容
- git - Git:安全地将我的(未推送的)提交移动到不同的分支?
- php - Woocommerce 从产品页面获取类别 ID
- amazon-web-services - AWS - 使用 cloud-init(用户数据字段)激活 conda 环境
- numpy - numpy - 为什么 np.multiply.reduce([], axis=None) 结果为 1?
- laravel - 不能将 0 或 1 存储为布尔 laravel postgresql
- react-native - 无法为反应原生部署 firebase 功能
- node.js - 如何在不访问路由器的情况下托管服务器?