Is there an option that allows the associated model to create its sub models/collections at initialization time? I have been using defaults object to have it do this but I was sure if this was the best practice or not.
Example:
var Model = Backbone.AssociatedModel.extend({
relations: [{
type: Backbone.One,
key: 'class',
relatedModel: ClassModel
}, {
type: Backbone.Many,
key: 'students',
relatedModel: StudentModel
}],
defaults: {
class: {},
students: []
}
});
var model = new Model();
var classModel = model.get('class');
var classView = new ClassView({model: classModel});
var studentsCollection = model.get('students');
var studentsView = new StudentsView({collection: studentCollection});
Is there a way I can do this without using the defaults object?
Is there an option that allows the associated model to create its sub models/collections at initialization time? I have been using
defaults
object to have it do this but I was sure if this was the best practice or not.Example:
Is there a way I can do this without using the defaults object?