Uncaught TypeError: Cannot read property 'initializedRelationships' of undefined version 2.0.10
heat opened this issue · 7 comments
Version info
DEBUG: -------------------------------
DEBUG: Ember : 3.8.0
DEBUG: Ember Data : 3.8.0
DEBUG: Firebase : 3.9.0
DEBUG: EmberFire : 0.0.0
DEBUG: jQuery : 3.3.1
DEBUG: Ember Bootstrap : 2.6.0
DEBUG: Ember Simple Auth : 1.8.2
DEBUG: -------------------------------
Emberfire installed
emberfire@2.0.10
Expected behavior
List all objects
Actual behavior
When try to load all store.findAll('bar')
.
Uncaught TypeError: Cannot read property 'initializedRelationships' of undefined
firebase.js:674 Uncaught TypeError: Cannot read property 'initializedRelationships' of undefined
at Application.getFirstEmbeddingParent (firebase.js:674)
at Application.isRecordEmbedded (firebase.js:580)
at Application.listenForChanges (firebase.js:169)
at Application.recordWasPushed (firebase.js:140)
at emberfire.js:44
at Array.forEach (<anonymous>)
at Class._emberfireHandleRecordPush (emberfire.js:40)
at Class._push (emberfire.js:76)
at Class.superWrapper [as _push] (utils.js:349)
at promise.then.adapterPayload (-private.js:7263)
When try to save a model. model.save()
.
TypeError: Cannot read property 'initializedRelationships' of undefined
at Bar.getFirstEmbeddingParent (firebase.js:674)
at Bar._getAbsoluteRef (firebase.js:649)
at Bar.updateRecord (firebase.js:405)
at Bar.createRecord (firebase.js:385)
at Ember.RSVP.Promise.resolve.then (-private.js:12802)
@heat thanks for your report.
Please note that the latest stable emberfire (v2.0.10) is compatible only with Ember v3.4, if you would like to use the latest ember, please try out the emberfire v3 beta.
More details: #553
Please share your experience with the new beta version. Everything works as expected?
@heat I was having this issue the other last week and it was because of a combination of my database rules and the way I was saving my asynchronous relationships. Check out these previous relationships docs: https://github.com/firebase/emberfire/blob/c75d1a4fe461b22be54d86370dac8d43a8c4c991/docs/guide/relationships.md#async.
Also, make sure that you're referencing the correct model in your hasMany
/belongsTo
.
For instance if you have a comment
model that belongsTo
a post, but your post model is:
// models/post.js
import DS from 'ember-data';
export default DS.Model.extend({
comments: DS.hasMany('comment', { async: true, inverse: null })
});
Make sure your DS.hasMany('comment'...
is the name of the actual model and not a pluralized version of the model name if that's not what it is.
Have the same issue after triggering save method of record in requestInvitation method of index controller.
ember -v
ember-cli: 3.11.0
node: 10.15.3
os: darwin x64
emberfire version - 2.0.10
ENV
firebase: {
apiKey: "AIzaSyDRRyc...",
authDomain: "libraryap...",
databaseURL: "https://libr...",
storageBucket: "libraryapp-...",
},
models/invitation.js
import DS from 'ember-data';
export default DS.Model.extend({
email: DS.attr('string')
});
controllers/index.js
import Controller from '@ember/controller';
import { computed } from '@ember/object';
export default Controller.extend({
emailFromValue: '',
header: 'Coming soon',
isDisabled: computed('emailFromValue', function() {
return !this.emailFromValue.match(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/);
}),
actions: {
changeEmailValue({ target: { value } }) {
this.set('emailFromValue', value);
},
requestInvitation(){
this.store.createRecord('invitation', { email: this.emailFromValue }).save();
alert('thank u for requesting!: ', this.store.invitation)
this.set('emailFromValue', '')
}
}
});
Error:
firebase.js:674 Uncaught TypeError: Cannot read property 'initializedRelationships' of undefined
at Class.getFirstEmbeddingParent (firebase.js:674)
at Class._getAbsoluteRef (firebase.js:649)
at Class.updateRecord (firebase.js:405)
at Class.createRecord (firebase.js:385)
at -private.js:13272
at tryCatcher (rsvp.js:335)
at invokeCallback (rsvp.js:506)
at rsvp.js:570
at rsvp.js:16
at invoke (backburner.js:335)
@TrueFirel please as mention here ttps://github.com//issues/566#issuecomment-471113352
you need update it to work with new ember.
@zoltan-nz Im using the version 3 and it
s work great.
@heat thanks for your report.
Please note that the latest stable emberfire (v2.0.10) is compatible only with Ember v3.4, if you would like to use the latest ember, please try out the emberfire v3 beta.
More details: #553
Please share your experience with the new beta version. Everything works as expected?
I'm seeing this issue as well. Few specs:
"ember-cli": "^3.4.4"
"emberfire": "^2.0.10"
I have one model for the whole application that only has 3 attributes that do not contain relationships. My firebase database has read
and write
set to true
, so I doubt the issue is pertaining to permissions. The issue appears to arise when calling record.save()
, I checked out the source for this -
https://github.com/firebase/emberfire/blob/aff7426015077137dd94b95dee2ef43199668ad1/addon/adapters/firebase.js#L696-L700
looks like this could be the issue? internalModel
not having _implicitRelationships
and _relationships.initializedRelationships
Not sure why these attributes are not set on the internalModel
object, but adding a check for the _implicitRelationships
and _relationships.initializedRelationships
attributes lets me save records now.
getFirstEmbeddingParent: function getFirstEmbeddingParent(internalModel) {
if (!internalModel._implicitRelationships) {
internalModel._implicitRelationships = null;
}
if (!internalModel._relationships) {
internalModel._relationships = {};
internalModel._relationships.initializedRelationships = null;
}
var relationships = assign({}, internalModel._implicitRelationships, internalModel._relationships.initializedRelationships);
var embeddingParentRel = undefined;
var relationshipKeys = Object.keys(relationships);
Not sure if there was a change to Ember Data or not... I'm using "ember-data": "~3.9.0"
, but this fixes the issue
Its compatible with ember
< 3.4 `