我们在后端 nodejs 服务中使用js-data-sql
DSSqlAdapter。我们的模型定义具有hasOne
如下定义的关系:
module.exports = {
name: 'covariance_predictions',
idAttribute: 'id',
relations: {
belongsTo: {
assets: {
localKey: 'asset_1_id',
localField: 'Covariance_Predictions'
}
},
hasOne: {
currencies: {
localField: 'currency',
localKey: 'currency_id'
}
}
}
};
我们使用以下方法调用适配器:
covariancePredictions.findAll(params, {
with: ['currencies']
})
问题
启用knex
调试后,我们发现它不使用left join
语句,而是使用后续 SQL 查询,例如:
sql: 'select "currencies".* from "currencies" where "id" in (?, ?, ?, ?, ?, ?, ?)' }
有谁知道如何让js-data-sql
DSSqlAdapter构建一个left join
代替?喜欢:
select "covariance_predictions".id, [...], "currencies".code from "covariance_predictions" left join "currencies" on "currencies".id = "covariance_predictions".currency_id;