Normalize the schema definition
This commit is contained in:
parent
a6ad39ba0f
commit
3830f0bfda
|
@ -103,6 +103,8 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
|
|||
properties = properties || {};
|
||||
settings = settings || {};
|
||||
|
||||
buildSchema(className, properties);
|
||||
|
||||
// every class can receive hash of data as optional param
|
||||
var ModelClass = function ModelConstructor(data, schema) {
|
||||
if (!(this instanceof ModelConstructor)) {
|
||||
|
@ -416,19 +418,21 @@ function buildSchema(name, properties, associations) {
|
|||
var type = getSchemaType(properties[p]);
|
||||
if (typeof type === 'string') {
|
||||
// console.log('Association: ' + type);
|
||||
associations.push({
|
||||
source: name,
|
||||
target: type,
|
||||
relation: Array.isArray(properties[p]) ? 'hasMany' : 'belongsTo',
|
||||
as: p
|
||||
});
|
||||
delete properties[p];
|
||||
if (Array.isArray(associations)) {
|
||||
associations.push({
|
||||
source: name,
|
||||
target: type,
|
||||
relation: Array.isArray(properties[p]) ? 'hasMany' : 'belongsTo',
|
||||
as: p
|
||||
});
|
||||
delete properties[p];
|
||||
}
|
||||
} else {
|
||||
var typeDef = {
|
||||
type: type
|
||||
};
|
||||
delete properties[p].type;
|
||||
for(var a in properties[p]) {
|
||||
for (var a in properties[p]) {
|
||||
typeDef[a] = properties[p][a];
|
||||
}
|
||||
properties[p] = typeDef;
|
||||
|
|
Loading…
Reference in New Issue