Using mix of AND and OR clause in sails and waterline

后端 未结 3 1563
没有蜡笔的小新
没有蜡笔的小新 2021-01-14 11:22

How can I use OR and AND clause in Sailsjs and its ORM Waterline? For example I have a table of books

 _______________________________________
| book_name |          


        
相关标签:
3条回答
  • 2021-01-14 11:49

    The following query should also work:

    const books = yield Book.find().where({
      author: 'Author-1',
      or: [{
        free: true,
      }, {
        public: true,
      }],
    });
    
    0 讨论(0)
  • 2021-01-14 11:49

    For doing so we can use the where api of Waterline, following is an example

    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
        }
    
    0 讨论(0)
  • 2021-01-14 11:51
      let booksResult=await Book.find().
                            where({author: "Author-1", 
                               or: [{ free: true  }, { public: true  }]
                            });
    
    
    0 讨论(0)
提交回复
热议问题