我试图获取所有与具有特定类别产品相关的具有相关功能的功能键,但收到以下所述的错误。我做错了什么?
我的表结构:
Product:
id -> int
category_id -> int (one-to-many)
FeatureProducts: (many-to-many)
id -> int
product_id -> int
feature_id -> int
Feature:
id -> int
value -> string
featurekey_id -> int (one-to-many)
FeatureKeys:
id -> int
type -> string
name -> string
text -> string
Product.query((qb) => {
qb.where('category_id', '=', params.category);
})
.belongsToMany(Featurekey)
.through(Feature)
.fetch({
withRelated: filters.populate || populate,
});
Error: Undefined binding(s) detected when compiling SELECT query: select `featurekey`.*, `feature`.`id` as `_pivot_id`, `feature`.`product_id` as `_pivot_product_id`, `feature`.`featurekey_id` as `_pivot_featurekey_id` from `featurekey` inner join `feature` on `feature`.`featurekey_id` = `featurekey`.`id` where `feature`.`product_id` = ?
答案 0 :(得分:0)
尝试更改您的代码
it()
代替此:
Product.query((qb) => {
qb.where('category_id', req.params.category);
})
.belongsToMany(Featurekey)
.through(Feature)
.fetch({
withRelated: filters.populate || populate,
});