diff --git a/lib/Lib/Core/Model.class.js b/lib/Lib/Core/Model.class.js index c80c85d0..af272cd9 100644 --- a/lib/Lib/Core/Model.class.js +++ b/lib/Lib/Core/Model.class.js @@ -267,7 +267,7 @@ var Model = module.exports = Class(function(){ * @return {[type]} [description] */ where: function(where){ - if (isString(where) && where) { + if (where && isString(where)) { where = { "_string": where } @@ -319,7 +319,7 @@ var Model = module.exports = Class(function(){ return this; }, /** - * 生成查询SQL 可用于子查询 + * 生成查询SQL 可用于子查询,返回一个promise * @param {[type]} options [description] * @return {[type]} [description] */ @@ -336,10 +336,11 @@ var Model = module.exports = Class(function(){ */ parseOptions: function(options, extraOptions){ var self = this; + var promise = null; + options = extend(this.options, this.parseWhereOptions(options), extraOptions); // 查询过后清空sql表达式组装 避免影响下次查询 this.options = {}; - var promise = null; //获取数据表下的字段信息 if (options.table) { promise = this.getTableFields(options.table); @@ -383,7 +384,7 @@ var Model = module.exports = Class(function(){ }; return item; }).join(','); - }; + }; options = self._optionsFilter(options, fields); return options; }); @@ -511,7 +512,7 @@ var Model = module.exports = Class(function(){ }) }, /** - * 插入多条数据 + * 插入多条数据,返回最后一个插入的ID * @param {[type]} data [description] * @param {[type]} options [description] * @param {[type]} replace [description] @@ -687,10 +688,10 @@ var Model = module.exports = Class(function(){ return this.parseOptions(options, { limit: 1 }).then(function(options){ - return self.db.select(options).then(function(data){ - var result = data ? data[0] : []; - return self._afterFind(result, options); - }) + return self.db.select(options); + }).then(function(data){ + var result = data ? data[0] : []; + return self._afterFind(result, options); }).then(function(result){ if (result === false) { return getPromise("_afterFind return false", true); @@ -698,6 +699,12 @@ var Model = module.exports = Class(function(){ return result; }) }, + /** + * select后置操作 + * @param {[type]} result [description] + * @param {[type]} options [description] + * @return {[type]} [description] + */ _afterSelect: function(result, options){ return result; },