Normalize the schema definition

This commit is contained in:
Raymond Feng 2013-06-21 14:04:24 -07:00
parent a6ad39ba0f
commit 3830f0bfda
1 changed files with 12 additions and 8 deletions

View File

@ -103,6 +103,8 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
properties = properties || {}; properties = properties || {};
settings = settings || {}; settings = settings || {};
buildSchema(className, properties);
// every class can receive hash of data as optional param // every class can receive hash of data as optional param
var ModelClass = function ModelConstructor(data, schema) { var ModelClass = function ModelConstructor(data, schema) {
if (!(this instanceof ModelConstructor)) { if (!(this instanceof ModelConstructor)) {
@ -416,6 +418,7 @@ function buildSchema(name, properties, associations) {
var type = getSchemaType(properties[p]); var type = getSchemaType(properties[p]);
if (typeof type === 'string') { if (typeof type === 'string') {
// console.log('Association: ' + type); // console.log('Association: ' + type);
if (Array.isArray(associations)) {
associations.push({ associations.push({
source: name, source: name,
target: type, target: type,
@ -423,6 +426,7 @@ function buildSchema(name, properties, associations) {
as: p as: p
}); });
delete properties[p]; delete properties[p];
}
} else { } else {
var typeDef = { var typeDef = {
type: type type: type