Skip to content

Commit

Permalink
Allow null properties for headless models
Browse files Browse the repository at this point in the history
  • Loading branch information
1602 committed Apr 15, 2013
1 parent 6ad4886 commit 8936278
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/model.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -445,7 +445,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));
}; };


Expand Down
1 change: 1 addition & 0 deletions lib/schema.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions test/relations.test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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();
}); });
}); });
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8936278

Please sign in to comment.