Given these snippets (hopefully complete enough for this question)…
ModelA.js (has many modelBs):
ModelBs = (function(_super) {
ModelB.prototype.bWithName = function(name) {
return this.find(function (b) {
return b.name == name;
});
}
})(Backbone.Collection);
return ModelA = (function(_super) {
...
ModelA.prototype.initialize = function() {
this.modelbs = new ModelBs(this.modelbs, {});
};
ModelA.prototype.bWithName = function(name) {
return this.modelbs.bWithName(name);
};
return modelA;
})(BaseModel);
ModelC.js (has one modelA):
ModelC.prototype.toString = function(opts) {
...
console.log(this.modelA); // defined...
console.log(this.modelA.modelBs); // defined...
console.log(this.modelA.bWithName("foo")); // undefined
...
}
In ModelC.js, why are this.modelA and this.modelA.modelBs defined, but this.modelA.bWithName() undefined, and how can I fix it?
This works: this.modelA.modelBs.first().
This returns undefined: this.modelA.modelBs.where({name:"foo"}).
In the web console, this works: modelZ.modelAs.first().bWithName("foo").attributes.
Are accessors or methods in general not available through other models?
Thanks-
Bah. The method was in fact available, but the strict equals (
===) was killing the search. In one instance I was trying to search with the wrong typeof name.Thanks for the input though!