Add required validation
This commit is contained in:
parent
024a6cb52f
commit
08505d1e78
|
@ -141,12 +141,13 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
|
||||||
}
|
}
|
||||||
// Add the id property
|
// Add the id property
|
||||||
if (idInjection) {
|
if (idInjection) {
|
||||||
|
|
||||||
ModelClass.prototype.__defineGetter__('id', function () {
|
ModelClass.prototype.__defineGetter__('id', function () {
|
||||||
return this.__data.id;
|
return this.__data.id;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set up the id property
|
// Set up the id property
|
||||||
properties.id = properties.id || { type: Number, id: 1 };
|
properties.id = properties.id || { type: Number, id: 1, generated: true };
|
||||||
if (!properties.id.id) {
|
if (!properties.id.id) {
|
||||||
properties.id.id = 1;
|
properties.id.id = 1;
|
||||||
}
|
}
|
||||||
|
@ -188,7 +189,8 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelClass.registerProperty = function (attr) {
|
ModelClass.registerProperty = function (attr) {
|
||||||
var DataType = properties[attr].type;
|
var prop = properties[attr];
|
||||||
|
var DataType = prop.type;
|
||||||
if(!DataType) {
|
if(!DataType) {
|
||||||
throw new Error('Invalid type for property ' + attr);
|
throw new Error('Invalid type for property ' + attr);
|
||||||
}
|
}
|
||||||
|
@ -203,6 +205,11 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
|
||||||
DataType = dataSource.getSchemaType(DataType);
|
DataType = dataSource.getSchemaType(DataType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(prop.required) {
|
||||||
|
var requiredOptions = typeof prop.required === 'object' ? prop.required : undefined;
|
||||||
|
ModelClass.validatesPresenceOf(attr, requiredOptions);
|
||||||
|
}
|
||||||
|
|
||||||
Object.defineProperty(ModelClass.prototype, attr, {
|
Object.defineProperty(ModelClass.prototype, attr, {
|
||||||
get: function () {
|
get: function () {
|
||||||
if (ModelClass.getter[attr]) {
|
if (ModelClass.getter[attr]) {
|
||||||
|
|
Loading…
Reference in New Issue