使用 Where 和 Include 失败对查询进行 Sequelize

Sequelize query with Where and Include failing

正在尝试查询 return 辆汽车和相关照片。这有效:

Vehicle.findAll({
        include: [db.photos]
    })

我得到如下输出:

{
    "id": 69,
    "make": "Ford",
    "model": "Fiesta",
    "photos": [
        {
            "id": 10,
            "photoUrl": "29_1.jpg",
            "vehicleId": 69
        },
        {
            "id": 11,
            "photoUrl": "29_2.jpg",
            "vehicleId": 69
        }
    ]
},

但这并没有,return只有汽车数据而没有照片:

Vehicle.findAll({
        where: { 
            make: { [Op.like]: '%' + make + '%' },
            model: { [Op.like]: '%' + model + '%' }
        }
    },
    {
        include: [db.photos]
    })

我做错了什么?

您没有正确使用 Model.findAll()Model.findAll()的签名是

public static async findAll(options: object): Promise<Array>

如你所见,它只接受一个参数options

尝试:

Vehicle.findAll({
  where: {
    make: { [Op.like]: '%' + make + '%' },
    model: { [Op.like]: '%' + model + '%' },
  },
  include: [db.photos],
});