时间:2019-11-21 09:14:13

标签: node.js sequelize.js

如果从1:N表的N个表中检索该值并将其包括在内,我想提取一个表的所有N个表值。

由于“分页”,我走了“极限”。

我尝试了很多方法。 我尝试过“ sequelize.literal”,但是很难得到想要的价格。

我可以在“子查询”中放入“子查询”吗?

有办法吗?

  const option = {
    include: [
      {
        model: ProductInformation,
        attributes: [
          'id',
          'size',
          'age',
          'price',
          'bidStartPrice',
          'quantity',
        ],
        where: {
          price: {
            [Op.between]: [
              startPrice,
              endPrice
            ]
          }
        }
      },
    ],
    attributes: [
      'id',
      'codeNumber',
      'kind',
      'breeding',
      'area',
      'memo',
    ],
    distinct: true,
    order: [['id', 'desc']],
    limit: 11,
    offset
  };

  Product.findAndCountAll(option);

结果:

{
  "status": 200,
  "result": true,
  "message": "success",
  "list": {
    "count": 1,
    "row": [
      {
        "id": 56,
        "codeNumber": "959515",
        "kind": "Nutritious",
        "breeding": "1",
        "area": "korea",
        "memo": "test",
        "productInformations": [
          {
            "id": 149,
            "size": "Special",
            "age": "12",
            "price": 12,
            "bidStartPrice": 2,
            "quantity": 0
          }
        ]
      }
    ]
  }
}



Want:
    "productInformations": [
      {
        "id": 149,
        "size": "Special",
        "age": "12",
        "price": 12,
        "bidStartPrice": 2,
        "quantity": 2
      },
      {
        "id": 150,
        "size": "King",
        "age": "13",
        "price": 300,
        "bidStartPrice": 3,
        "quantity": 5
      }
    ]




0 个答案:

没有答案