Allow null properties for headless models

This commit is contained in:
Anatoliy Chakkaev 2013-04-15 16:58:03 +04:00 committed by Raymond Feng
parent a67f75f0be
commit eecbd32d07
3 changed files with 8 additions and 4 deletions

View File

@ -444,7 +444,9 @@ AbstractClass.destroyAll = function destroyAll(cb) {
if (stillConnecting(this.schema, this, arguments)) return; if (stillConnecting(this.schema, this, arguments)) return;
this.schema.adapter.destroyAll(this.modelName, function (err) { this.schema.adapter.destroyAll(this.modelName, function (err) {
cb(err); if ('function' === typeof cb) {
cb(err);
}
}.bind(this)); }.bind(this));
}; };

View File

@ -176,6 +176,7 @@ Schema.prototype.define = function defineClass(className, properties, settings)
if (args.length == 1) properties = {}, args.push(properties); if (args.length == 1) properties = {}, args.push(properties);
if (args.length == 2) settings = {}, args.push(settings); if (args.length == 2) settings = {}, args.push(settings);
properties = properties || {};
settings = settings || {}; settings = settings || {};
// every class can receive hash of data as optional param // every class can receive hash of data as optional param

View File

@ -183,8 +183,8 @@ describe('relations', function() {
t.should.be.an.instanceOf(Tag); t.should.be.an.instanceOf(Tag);
ArticleTag.findOne(function(e, at) { ArticleTag.findOne(function(e, at) {
should.exist(at); should.exist(at);
at.tagId.should.equal(t.id); at.tagId.toString().should.equal(t.id.toString());
at.articleId.should.equal(article.id); at.articleId.toString().should.equal(article.id.toString());
done(); done();
}); });
}); });
@ -220,7 +220,8 @@ describe('relations', function() {
Article.findOne(function(e, article) { Article.findOne(function(e, article) {
article.tags(function(e, tags) { article.tags(function(e, tags) {
var len = tags.length; 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); should.not.exist(e);
article.tags(true, function(e, tags) { article.tags(true, function(e, tags) {
tags.should.have.lengthOf(len - 1); tags.should.have.lengthOf(len - 1);