Sequelize find based on association

前端 未结 3 1537
时光说笑
时光说笑 2020-12-23 19:53

How would I use Sequelize to find all people where a column in the relation satisfies a condition?

An example would be to find all Books whose author\'s last name is

3条回答
  •  爱一瞬间的悲伤
    2020-12-23 20:16

    In the newest version of Sequilize (5.9.0) the method proposed by @c.hill does not work.

    Now you need to do the following:

    return Book.findAll({
        where: {
            '$Authors.lastName$': 'Testerson'
        },
        include: [
            {model: Author, as: Author.tableName}
        ]
    });
    

提交回复
热议问题