Hello I have some functionality in my backbone application, that allows the user to make a selection via a select menu and that choice fires a get request, the response is added to a collection,
this.archived.fetch({
success:function() {
this.archived.each(function(model){
if(model.get('organisation_id') == $('.js-filter-by-organisation').val()){
model.set('visible', true);
} else if($('.js-filter-by-organisation').val() == "all") {
model.set('visible', true);
}
this.collection.add(model);
});
}
});
My problem is that when I then try and use the models added to the collection some of the attributes are the wrong type. For example in an archived model I have an attribute called organisations this should be a model, but when I run the fetch and then look at the results in the collection organisations is an object, however on my model I set this attribute to be an model on initialization.
Am I doing something wrong when I fetch from server, and add the results to my collection?