2014-09-29 44 views
0

我要考虑的只有 'req.query.p' 被定义在where子句:Sequelize '其中' 只有req.query定义

exports.select = function(req, res) { 
     db.Pelicula 
      .findAndCountAll({ 
       limit : req.query.limit, 
       offset : req.query.offset, 
       where : ["nombre = ?", req.query.p] 
      }) 
      .success(function(resp){ 
       console.log(JSON.stringify(resp.rows, null, 4).bold.get); 
       res.json({peliculas : resp.rows, meta : { total : resp.count}}); 
      }); 
} 

回答

0

你可以这样做:

where : req.query.p ? ["nombre = ?", req.query.p] : null 
+0

如果req.query.p是'val1:1'怎么办? 我想通过val1列进行过滤 – jFranciscov 2014-09-29 16:45:55