不要怂,就是干,撸起袖子干!

Commit 0aba244e by Mick Hansen

Merge pull request #554 from innofluence/543fix

Fix Model.find(0)
2 parents 3580e56d de46a5be
...@@ -19,4 +19,5 @@ env: ...@@ -19,4 +19,5 @@ env:
language: node_js language: node_js
node_js: node_js:
- 0.8 - 0.8
\ No newline at end of file
\ No newline at end of file
...@@ -155,7 +155,7 @@ module.exports = (function() { ...@@ -155,7 +155,7 @@ module.exports = (function() {
options.attributes = optAttributes.join(', ') options.attributes = optAttributes.join(', ')
} }
if (options.where) { if (options.hasOwnProperty('where')) {
options.where = this.getWhereConditions(options.where, tableName) options.where = this.getWhereConditions(options.where, tableName)
query += " WHERE <%= where %>" query += " WHERE <%= where %>"
} }
......
...@@ -224,7 +224,7 @@ module.exports = (function() { ...@@ -224,7 +224,7 @@ module.exports = (function() {
options.attributes = optAttributes.join(', ') options.attributes = optAttributes.join(', ')
} }
if(options.where) { if(options.hasOwnProperty('where')) {
options.where = QueryGenerator.getWhereConditions(options.where) options.where = QueryGenerator.getWhereConditions(options.where)
query += " WHERE <%= where %>" query += " WHERE <%= where %>"
} }
......
...@@ -2,6 +2,7 @@ if(typeof require === 'function') { ...@@ -2,6 +2,7 @@ if(typeof require === 'function') {
const buster = require("buster") const buster = require("buster")
, Sequelize = require("../index") , Sequelize = require("../index")
, Helpers = require('./buster-helpers') , Helpers = require('./buster-helpers')
, _ = require('underscore')
, dialect = Helpers.getTestDialect() , dialect = Helpers.getTestDialect()
} }
...@@ -486,6 +487,31 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -486,6 +487,31 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}.bind(this)) }.bind(this))
}) })
it('always honors ZERO as primary key', function(_done) {
var permutations = [
0,
'0',
{where: {id: 0}},
{where: {id: '0'}}
]
, done = _.after(2 * permutations.length, _done);
this.User.create({name: 'jack'}).success(function (jack) {
this.User.create({name: 'jill'}).success(function (jill) {
permutations.forEach(function(perm) {
this.User.find(perm).done(function(err, user) {
expect(err).toBeNull();
expect(user).toBeNull();
done();
}).on('sql', function(s) {
expect(s.indexOf(0)).not.toEqual(-1);
done();
})
}.bind(this))
}.bind(this))
}.bind(this))
})
describe('eager loading', function() { describe('eager loading', function() {
before(function() { before(function() {
this.Task = this.sequelize.define('Task', { title: Sequelize.STRING }) this.Task = this.sequelize.define('Task', { title: Sequelize.STRING })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!