I have a backbone model that is mix of single attributes, other models and collections.
To create this model and collection within a parent model scenario my model code looks like this,
App.Models.Project = Backbone.Model.extend({
urlRoot: "http://" + App.API_ROOT + "/project",
defaults: {
visible: true
},
initialize: function() {
var clients = this.get('clients');
var pm = this.get('projectmanager');
this.set('project_manager', new App.Models.User(pm));
var sp = this.get('salesperson');
this.set('sales_person', new App.Models.User(sp));
this.set('clients', new App.Models.Client(clients));
this.set('status_text', this.getStatusText(this.get('status')));
},
getStatusText: function(status) {
switch(status) {
case "0":
return 'Archived';
break;
case "1":
return 'Pending';
break;
case "2":
return 'Active';
break;
case "3":
return 'Complete';
break;
}
}
});
However occassional a model will be returned where the client attribute has not been set to a model, but has remained as an object, why would this be? Is there a better way to achieve my goal? Of models and collections within a parent model?