I’ve encountered an odd problem with Ember Data (3.12.6 - latest LTS).
Specifically, I have this type of thing:
somethingObserver: observer('record.SomeRelationship', function() {
record.get('SomeRelationship').then(val => {
console.log(val.get('isLoading'),val.get('SomeProperty');
});
})
(and yes, there might be better ways of doing this without the observer, but I don’t think that affects the validity of the example).
The console.log here will output:
true undefined
which seems like it should be impossible?
Even more weird, if I expand it to do:
somethingObserver: observer('record.SomeRelationship', function() {
record.get('SomeRelationship').then(val => {
console.log(val.get('isLoading'),val.get('SomeProperty');
const rightVal = store.peekRecord(val.constructor.modelName,val.id);
console.log(rightVal.get('isLoading'),rightVal.get('SomeProperty');
});
})
then I get output of:
true undefined
false TheCorrectValue
In other words, the object returned from the then
is not finished loading, but if I do a peekRecord
into the store for the exact same object, it gives me the proper fully defined object!
I’ve verified that the over-the-network traffic looks good, and everything is coming back successfully.
The only thing that is interesting, is if I do an Ember.guidFor
on both the object returned by the then
and the object coming from peekRecord
, I get:
- The object from the
then
: ember1234 - The object from the
peekRecord
: st4567
I’m not sure if the difference in prefix on the guidFor
tells us anything interesting?
Would anyone be able to point me in the right direction for debugging this? (I’m fine with stepping into the Ember Data code, but would appreciate some insight as to where one could look.)
Thanks in advance!