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

Commit bfed61fa by Jan Aagaard Meier

Fix 0 primary key

1 parent 5cc12629
......@@ -155,7 +155,7 @@ module.exports = (function() {
options.attributes = optAttributes.join(', ')
}
if (options.where) {
if (options.where !== undefined) {
options.where = this.getWhereConditions(options.where, tableName)
query += " WHERE <%= where %>"
}
......
......@@ -2,6 +2,7 @@ if(typeof require === 'function') {
const buster = require("buster")
, Sequelize = require("../index")
, Helpers = require('./buster-helpers')
, _ = require('underscore')
, dialect = Helpers.getTestDialect()
}
......@@ -486,6 +487,35 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}.bind(this))
})
it('always honors ZERO as primary key', function(_done) {
var permutations = [
{v: 0, k: 'intV'},
{v: '0', k: 'intV'},
{v: {where: {id: 0}}, k: 'intV'},
{v: {where: {id: '0'}}, k: 'strV'}
]
, SQLs = {
strV: "SELECT * FROM `Users` WHERE `Users`.`id`='0' LIMIT 1;",
intV: "SELECT * FROM `Users` WHERE `Users`.`id`=0 LIMIT 1;"
}
, 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.v).done(function(err, user) {
expect(err).toBeNull();
expect(user).toBeNull();
done();
}).on('sql', function(s) {
expect(s).toEqual(SQLs[perm.k]);
done();
})
}.bind(this))
}.bind(this))
}.bind(this))
})
describe('eager loading', function() {
before(function() {
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!