Given I have model mA, collection cA, model mB and collection cB.
mA contains a member that is the collection cB. mB contains a member that is the model mA. Models of type A are parents of type B. When I create a parent I want all of the children. When I create a child/children I want that child's parent. This however creates a cycle. My problems are two fold. The first problem I have is that in mB I get an ‘Undefined is not a function’ on the line var modelA = new mA();
when creating a new collection cA. Removing their interdependency stops the error but doesn’t help me. My second problem is how can I know if mB is created from mA and if so do not create a new cA member.
define(['cB'],function(cB){
var mA = Backbone.Model.extend({
parse:function(res,opt){
var colB = new cB(res.id);
colB.fetch();
res.children = colB;
return res;
}
});
return mA;
});
define(['mA'],function(mA){
var mB = Backbone.Model.extend({
parse:function(res,opt){
var modelA = new mA();
modelA.set({id:res.parent_id})
modelA.fetch();
res.parent = modelA;
return res;
}
});
return mB;
});
var colA = new cA();
- How can I define that each file needs the other without the ‘Undefined is not a function’ error?
- How can mB know if it was created from mA?