【问题标题】:How to fix: Undefined binding(s) detected when compiling SELECT query如何修复:编译 SELECT 查询时检测到未定义的绑定
【发布时间】:2019-06-01 15:20:12
【问题描述】:

我试图获取与具有特定类别的产品相关的所有具有相关功能的功能键,但收到如下所述的错误。我做错了什么?

我的表结构:

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` = ?

【问题讨论】:

    标签: javascript sql node.js knex.js bookshelf.js


    【解决方案1】:

    尝试更改您的代码

    Product.query((qb) => {
          qb.where('category_id', req.params.category);
        })
          .belongsToMany(Featurekey)
          .through(Feature)
          .fetch({
            withRelated: filters.populate || populate,
          });
    

    而不是这个:

     Product.query((qb) => {
              qb.where('category_id', '=', params.category);
            })
              .belongsToMany(Featurekey)
              .through(Feature)
              .fetch({
                withRelated: filters.populate || populate,
              });
    

    【讨论】:

      猜你喜欢
      • 2019-06-18
      • 2017-12-04
      • 2017-12-15
      • 1970-01-01
      • 2020-05-30
      • 2021-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多