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

Commit ffc8030e by Daniel Durante

Smart where object will no longer try to handle NULLs (as Sequelize currently do…

…esn't support it as-is).
1 parent 5b617de1
Showing with 45 additions and 3 deletions
......@@ -88,9 +88,12 @@ var Utils = module.exports = {
type = typeof where[i]
_where[i] = _where[i] || {}
if (Array.isArray(where[i])) {
if (where[i] === null) {
// skip nulls
}
else if (Array.isArray(where[i])) {
_where[i].in = _where[i].in || []
_where[i].in.concat(where[i]);
_where[i].in.concat(where[i])
}
else if (type === "object") {
Object.keys(where[i]).forEach(function(ii) {
......
......@@ -907,7 +907,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
describe('special where conditions', function() {
describe('special where conditions/smartWhere object', function() {
beforeEach(function(done) {
var self = this
......@@ -919,6 +919,45 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it('should be able to retun a record with primaryKey being null for new inserts', function(done) {
var Session = this.sequelize.define('Session', {
token: { type: DataTypes.TEXT, allowNull: false },
lastUpdate: { type: DataTypes.DATE, allowNull: false }
}, {
charset: 'utf8',
collate: 'utf8_general_ci',
omitNull: true
})
, User = this.sequelize.define('User', {
name: { type: DataTypes.STRING, allowNull: false, unique: true },
password: { type: DataTypes.STRING, allowNull: false },
isAdmin: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false }
}, {
charset: 'utf8',
collate: 'utf8_general_ci'
})
User.hasMany(Session, { as: 'Sessions' })
Session.belongsTo(User)
Session.sync({ force: true }).success(function() {
User.sync({ force: true }).success(function() {
User.create({name: 'Name1', password: '123', isAdmin: false}).success(function(user) {
var sess = Session.build({
lastUpdate: new Date(),
token: '123'
})
user.addSession(sess).success(function(u) {
expect(u.token).to.equal('123')
done()
})
})
})
})
})
it('should be able to find a row between a certain date', function(done) {
this.User.findAll({
where: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!