Adds relation fields to objects

This commit is contained in:
Florent Vilmart
2016-04-08 07:42:02 -04:00
parent de2a2ee245
commit a770c4cba8
4 changed files with 55 additions and 0 deletions

View File

@@ -634,6 +634,24 @@ class Schema {
}
return false;
};
getRelationFields(className) {
if (this.data && this.data[className]) {
let classData = this.data[className];
return Object.keys(classData).filter((field) => {
return classData[field].startsWith('relation');
}).reduce((memo, field) => {
let type = classData[field];
let className = type.slice('relation<'.length, type.length - 1);
memo[field] = {
__type: 'Relation',
className: className
};
return memo;
}, {});
}
return {};
}
}
// Returns a promise for a new Schema.

View File

@@ -732,6 +732,11 @@ function untransformObject(schema, className, mongoObject, isNestedObject = fals
mongoObject[key], true);
}
}
if (!isNestedObject) {
let relationFields = schema.getRelationFields(className);
Object.assign(restObject, relationFields);
}
return restObject;
default:
throw 'unknown js type';