diff --git a/lib/model.js b/lib/model.js index cf214bd1..1c6457db 100644 --- a/lib/model.js +++ b/lib/model.js @@ -444,7 +444,9 @@ AbstractClass.destroyAll = function destroyAll(cb) { if (stillConnecting(this.schema, this, arguments)) return; this.schema.adapter.destroyAll(this.modelName, function (err) { - cb(err); + if ('function' === typeof cb) { + cb(err); + } }.bind(this)); }; diff --git a/lib/schema.js b/lib/schema.js index 0ea107d8..96205f93 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -176,6 +176,7 @@ Schema.prototype.define = function defineClass(className, properties, settings) if (args.length == 1) properties = {}, args.push(properties); if (args.length == 2) settings = {}, args.push(settings); + properties = properties || {}; settings = settings || {}; // every class can receive hash of data as optional param diff --git a/test/relations.test.js b/test/relations.test.js index 9d88a1d4..ef7c63cf 100644 --- a/test/relations.test.js +++ b/test/relations.test.js @@ -183,8 +183,8 @@ describe('relations', function() { t.should.be.an.instanceOf(Tag); ArticleTag.findOne(function(e, at) { should.exist(at); - at.tagId.should.equal(t.id); - at.articleId.should.equal(article.id); + at.tagId.toString().should.equal(t.id.toString()); + at.articleId.toString().should.equal(article.id.toString()); done(); }); }); @@ -220,7 +220,8 @@ describe('relations', function() { Article.findOne(function(e, article) { article.tags(function(e, tags) { var len = tags.length; - article.tags.remove(tags[0], function(e, at) { + tags.should.not.be.empty; + article.tags.remove(tags[0], function(e) { should.not.exist(e); article.tags(true, function(e, tags) { tags.should.have.lengthOf(len - 1);