如何在Sailsjs及其ORM水道中使用OR和and子句?例如,我有一张书表
_______________________________________
| book_name | author | free | public |
_______________________________________
| Book-A | Author-1 | false | true |
---------------------------------------
| Book-B | Author-1 | true | true |
---------------------------------------
| Book-C | Author-1 | false | false |
---------------------------------------
| Book-D | Author-2 | true | true |
---------------------------------------我想得到由作者-1的图书,要么是公开的或免费的,即图书-A和图书-B。如何用Sails.js编写这个查询
发布于 2014-04-16 21:13:26
为此,我们可以使用Waterline的where api,下面是一个示例
Book.find().where( { or : [ { free : true }, { public: true } ] })
.where( { author : "Author-1" } )
.exec( function (err, books) {
//Books will be an array containing all the books that matches this criteria
//Some code here
}发布于 2016-08-11 13:58:15
以下查询也应有效:
const books = yield Book.find().where({
author: 'Author-1',
or: [{
free: true,
}, {
public: true,
}],
});发布于 2019-04-16 06:50:23
let booksResult=await Book.find().
where({author: "Author-1",
or: [{ free: true }, { public: true }]
});https://stackoverflow.com/questions/23120258
复制相似问题