All my sample codes using the Appcelerator platform
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

40 lines
1.2 KiB

var Arrow = require('arrow'),
_ = require('lodash');
/**
* Creates models from your schema (see "fetchSchema" for more information on the schema).
*/
exports.createModelsFromSchema = function () {
var self = this,
models = {};
// TODO: Iterate through the models in your schema.
Object.keys(self.metadata.schema.objects).forEach(function (modelName) {
var object = self.metadata.schema.objects[modelName],
fields = {}, private = null;
Object.keys(object).forEach(function (fieldName) {
var field = object[fieldName];
if (fieldName !== 'id') {
// TODO: Define the Arrow field definitions based on the schema.
fields[fieldName] = {
type: field.type || String,
required: field.required
};
}
});
models[self.name + '/' + modelName] = Arrow.Model.extend(self.name + '/' + modelName, {
name: self.name + '/' + modelName,
autogen: !!self.config.modelAutogen, // Controls if APIs are automatically created for this model.
fields: fields,
connector: self,
logger: self.logger,
generated: true,
// cache Facebook attrs in the model to save a roundtrip
"private": self.metadata.schema.private[modelName]
});
});
self.models = _.defaults(self.models || {}, models);
};