implementation

Signed-off-by: Yaapa Hage <hage.yaapa@in.ibm.com>
This commit is contained in:
Yaapa Hage 2020-11-06 20:19:49 +05:30
parent d6a28f6aa1
commit 92286e14c3
2 changed files with 11 additions and 6 deletions

View File

@ -355,6 +355,11 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
forceId = false;
}
// Make id value mandatory if it is not autogenerated
if (!idProp.generated) {
ModelClass.validatesPresenceOf(idName);
}
if (forceId) {
ModelClass.validatesAbsenceOf(idName, {if: 'isNewRecord'});
}

View File

@ -15,7 +15,7 @@ const uid = require('./helpers/uid-generator');
let ds;
const ValidationError = require('..').ValidationError;
describe.only('id property', function() {
describe('id property', function() {
before(function() {
ds = getSchema();
});
@ -74,7 +74,7 @@ describe.only('id property', function() {
// If id is not autogenerated, forceId is not applicable and a value must be specified
it('should require id value', async () => {
await IdCheckC.create({name: 'Pablo'}).should.be.rejected();
await IdCheckC.create({name: 'Pablo'}).should.be.rejectedWith({statusCode: 422});
});
// If id is not autogenerated, forceId is not applicable and a value can be specified
@ -96,7 +96,7 @@ describe.only('id property', function() {
// If id is not autogenerated, forceId is not applicable and a value must be specified
it('should require id value', async () => {
await IdCheckD.create({name: 'Pablo'}).should.be.rejected();
await IdCheckD.create({name: 'Pablo'}).should.be.rejectedWith({statusCode: 422});
});
// If id is not autogenerated, forceId is not applicable and a value can be specified