Skip to content

Commit

Permalink
Fix: fix limit 1 for find method
Browse files Browse the repository at this point in the history
  • Loading branch information
welefen committed Feb 23, 2016
1 parent 9312efb commit 33918c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/model/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ export default class extends Base {
async parseOptions(oriOpts, extraOptions){
let options = think.extend({}, this._options);
if (think.isObject(oriOpts)) {
options = think.extend(options, oriOpts, extraOptions);
options = think.extend(options, oriOpts);
}
if(extraOptions){
options = think.extend(options, extraOptions);
}
//clear options
this._options = {};
Expand All @@ -109,8 +112,8 @@ export default class extends Base {
options.table += ' AS ' + options.alias;
}

if(!think.isObject(oriOpts)){
options = think.extend(options, this.parseWhereOptions(oriOpts, extraOptions));
if(oriOpts !== undefined && !think.isObject(oriOpts)){
options = think.extend(options, this.parseWhereOptions(oriOpts));
}
//check where key
if(options.where && !think.isEmpty(schema)){
Expand Down
6 changes: 3 additions & 3 deletions test/model/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ describe('model/base.js', function(){
return Promise.resolve({
insertId: 1000
});
}else if(sql.trim() === "SELECT * FROM `think_user` WHERE ( `id` = 897 )"){
}else if(sql.trim() === "SELECT * FROM `think_user` WHERE ( `id` = 897 ) LIMIT 1"){
return Promise.resolve([]);
}else if(sql.trim() === "SELECT * FROM `think_user` WHERE ( `id` = 898 )"){
}else if(sql.trim() === "SELECT * FROM `think_user` WHERE ( `id` = 898 ) LIMIT 1"){
return Promise.resolve([{
id: 898
}]);
Expand Down Expand Up @@ -776,7 +776,7 @@ describe('model/base.js', function(){
})
it('find', function(done){
instance.where({id: 100}).find().then(function(data){
assert.equal(instance.getLastSql(), "SELECT * FROM `think_user` WHERE ( `id` = 100 )");
assert.equal(instance.getLastSql(), "SELECT * FROM `think_user` WHERE ( `id` = 100 ) LIMIT 1");
assert.deepEqual(data, { id: 7565, title: 'title1', cate_id: 1, cate_no: 0 })
done();
})
Expand Down

0 comments on commit 33918c4

Please sign in to comment.