首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >和和或子句在帆和水线中的使用

和和或子句在帆和水线中的使用
EN

Stack Overflow用户
提问于 2014-04-16 21:13:26
回答 3查看 6.3K关注 0票数 3

如何在Sailsjs及其ORM水道中使用OR和and子句?例如,我有一张书表

代码语言:javascript
复制
 _______________________________________
| 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编写这个查询

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-04-16 21:13:26

为此,我们可以使用Waterline的where api,下面是一个示例

代码语言:javascript
复制
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
    }
票数 2
EN

Stack Overflow用户

发布于 2016-08-11 13:58:15

以下查询也应有效:

代码语言:javascript
复制
const books = yield Book.find().where({
  author: 'Author-1',
  or: [{
    free: true,
  }, {
    public: true,
  }],
});
票数 5
EN

Stack Overflow用户

发布于 2019-04-16 06:50:23

代码语言:javascript
复制
  let booksResult=await Book.find().
                        where({author: "Author-1", 
                           or: [{ free: true  }, { public: true  }]
                        });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23120258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档