After updating a very large app from 2.x to 3.28, I’ve encountered issues with async belongsTo relationships in our app. Specifically, we have Supplier and Client models, each of which extend from an Organization model. This all worked perfectly in the past. They are serialized separately and have separate endpoints in the API, but are one table in the backend and share many attributes.
The error we’re now seeing is the following:
-private.js:1038 Uncaught TypeError: Cannot read properties of undefined (reading 'kind')
at notifyRelationship (-private.js:1038:1)
at notifyChanges (-private.js:1024:1)
at -private.js:1283:1
at NotificationManager.notify (-private.js:6972:1)
at InternalModel.notifyBelongsToChange (-private.js:6345:1)
at -private.js:7456:1
at Map.forEach (<anonymous>)
at -private.js:7454:1
at Map.forEach (<anonymous>)
at RecordDataStoreWrapper._flushNotifications (-private.js:7450:1)
The issue is in notifyChanges function (see here: data/notify-changes.ts at 9889ebbd4eec162dba17bb00126ee71e49d04bce · emberjs/data · GitHub)
The record argument will typically be a record (e.g. Comment) and key will be a valid relationship (e.g. “author”), but when it gets to my Supplier record, it’s looking for a key called “organizations”. There’s no such relationship defined though and, again, this never happened prior to the upgrade.
I did notice if I remove the hasMany relationships (address & note) in Organization, the issue goes away. So I am guessing the mix up in notifyChanges results from the fact that Address and Note both belong-to Organization and it would be resolved by having a redundancy of those relationships on Supplier and Client and redundancy where I am using a single relationship (to Organization) currently for components using Address/Note.
If there’s a trick anyone knows to avoid this, that would be awesome. Sorry, this is probably a headache to follow…