Implemented hasOne destroy()

This commit is contained in:
Fabien Franzen 2014-08-20 15:58:45 +02:00
parent 123b2558a1
commit 12ebaf77f2
2 changed files with 31 additions and 2 deletions

View File

@ -1431,8 +1431,14 @@ HasOne.prototype.update = function (targetModelData, cb) {
};
HasOne.prototype.destroy = function (cb) {
this.fetch(function(err, inst) {
if (inst instanceof ModelBaseClass) {
inst.destroy(cb);
} else {
cb(new Error('HasOne relation ' + definition.name
+ ' is empty'));
}
});
};
/**

View File

@ -1269,6 +1269,29 @@ describe('relations', function () {
});
});
it('should destroy the related item on scope', function(done) {
Supplier.findById(supplierId, function(e, supplier) {
should.not.exist(e);
should.exist(supplier);
supplier.account.destroy(function(err) {
should.not.exist(e);
done();
});
});
});
it('should get the related item on scope - verify', function(done) {
Supplier.findById(supplierId, function(e, supplier) {
should.not.exist(e);
should.exist(supplier);
supplier.account(function(err, act) {
should.not.exist(e);
should.not.exist(act);
done();
});
});
});
});
describe('hasAndBelongsToMany', function () {