problem
I'd like to make the models actual JS and have them export configurations, as well as custom scripts. Right now having a
model.json
with the model config and then an optional extra
model.js
for a custom script feels a bit grafted together, and it's just more for a developer to need to keep track of. I'd rather have a single
model.js
file with all this information. And since we have the (model) generators at our disposal, I don't think this will be overwhelming for a developer to understand or use.
proposed solution
This is by no means final, but a generated model should probably look more like the below sample. Notes:
* "name" and "config" would come from
alloy generate model
* migrations would be added at compile time, if necessary
var Alloy = require('alloy');
var name = "nameFromGenerate";
var config = {
"columns": {
"count": "Int"
},
"defaults": {
"count": 0
},
"adapter": {
"type": "properties",
"prefix": "app"
}
};
var Model = Alloy.M(name, config);
///////////////////////////////////////////////////////
///// INSERT CODE HERE TO EXTEND MODEL DEFINITION /////
///////////////////////////////////////////////////////
var Collection = Alloy.Backbone.Collection.extend({model:Model});
Collection.prototype.config = Model.prototype.config;
exports.Model = Model;
exports.Collection = Collection;
This should be resolved by ALOY-193. Update this ticket if it is not.