Don't know how to reproduce yet outside a complex app...
ED 2.18.2
Triggered by fetchLink
vendor-3bd14d61504f3d17c7c371655fee128d.js:53572 Uncaught TypeError: Cannot read property 'get' of undefined
at BelongsToRelationship.addInternalModel (vendor-3bd14d61504f3d17c7c371655fee128d.js:142002)
at BelongsToRelationship.addInternalModel (vendor-3bd14d61504f3d17c7c371655fee128d.js:143153)
at vendor-3bd14d61504f3d17c7c371655fee128d.js:143209
at tryCatcher (vendor-3bd14d61504f3d17c7c371655fee128d.js:65295)
at invokeCallback (vendor-3bd14d61504f3d17c7c371655fee128d.js:65477)
at publish (vendor-3bd14d61504f3d17c7c371655fee128d.js:65462)
at Queue.invoke (vendor-3bd14d61504f3d17c7c371655fee128d.js:27963)
at Queue.flush (vendor-3bd14d61504f3d17c7c371655fee128d.js:27848)
at DeferredActionQueues.flush (vendor-3bd14d61504f3d17c7c371655fee128d.js:28035)
at Backburner.end (vendor-3bd14d61504f3d17c7c371655fee128d.js:28169)
Relationship.prototype.addInternalModel = function addInternalModel(internalModel, idx) {
if (!this.members.has(internalModel)) {
this.members.addWithIndex(internalModel, idx);
this.notifyRecordRelationshipAdded(internalModel, idx);
if (this.inverseKey) {
// ----- internalModel._relationships is undefined here!
internalModel._relationships.get(this.inverseKey).addInternalModel(this.internalModel);
} else {
if (!internalModel._implicitRelationships[this.inverseKeyForImplicit]) {
internalModel._implicitRelationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: { async: this.isAsync }, type: this.parentType });
}
internalModel._implicitRelationships[this.inverseKeyForImplicit].addInternalModel(this.internalModel);
}
this.internalModel.updateRecordArrays();
}
this.setHasData(true);
};
Turned out to be caused by the same issue as #5398
It would be nice if the Model classes could do a schema verification phase during the construction process. Would this be feasible? Or could a test be created for each model by the blueprint that would run a verification?
This is what I had: Assume a 1:1 relationship between pet 1---1 owner and pet 1---1 vet. Yes, bad example, but can't think of a better one.
model:pet
owner: belongsTo('person'),
vet: belongsTo('person')
model:person
pet: belongsTo('pet')
Adding a pet to an owner worked, but adding a pet to a vet failed as above.
Fix:
model:pet
owner: belongsTo('person', {inverse:null}),
vet: belongsTo('person', {inverse:null})
model:person
pet: belongsTo('pet', {inverse:null})
Interestingly this worked in older ED versions without specifying inverse: null.
@BryanCrotaz in older ED versions, if you didn't specify the inverse, whichever (owner / vet) you accessed first would get the relationship and the other would be broken (albeit silently).
You should have gotten an error here though? We do verify inverses are configured in a valid way. Let's add a test case for this setup to figure out why we didn't.
Most helpful comment
This is what I had: Assume a 1:1 relationship between
pet 1---1 ownerandpet 1---1 vet. Yes, bad example, but can't think of a better one.Adding a pet to an owner worked, but adding a pet to a vet failed as above.
Fix:
Interestingly this worked in older ED versions without specifying
inverse: null.