Persistence is unreliable
See original GitHub issuee.g.
DEBUG: -------------------------------
DEBUG: Ember : 2.10.1
DEBUG: Ember Data : 2.10.0
DEBUG: Firebase : 3.6.4
DEBUG: EmberFire : 0.0.0 (<<<< this doesn't seem to be correct, I'm using 2.0.5)
DEBUG: jQuery : 3.1.1
DEBUG: -------------------------------
Test case
models/conversation.js
export default DS.Model.extend({
invitees: DS.hasMany('user', { async: true, inverse: 'invitedConversations' })
});
models/user.js
export default DS.Model.extend({
invitedConversations: DS.hasMany('conversation', { async: true, inverse: 'invitees' })
});
routes/conversation.js
export default Ember.Route.extend({
model(params) {
return RSVP.hash({
conversation: this.get('store').query('conversation', {
orderBy: 'slug',
equalTo: params.conversation_slug
}),
});
},
actions: {
addInvitee(conversation, invitee) {
conversation.get('invitees').addObject(invitee);
invitee.get('invitedConversations').addObject(conversation);
},
removeInvitee(conversation, invitee) {
conversation.get('invitees').removeObject(invitee);
invitee.get('invitedConversations').removeObject(conversation);
},
saveInvitees(conversation) {
conversation.save().then(() => {
conversation.get('invitees').forEach((invitee) => {
return invitee.save();
});
});
}
}
});
I have a component that uses route-action
to call addInvitee
, removeInvitee
and saveInvitees
.
Steps to reproduce
- With both
conversation.invitees
anduser.invitedConversations
empty, I calladdInvitee
to add a dirty many-to-many relationship - Call
saveInvitees
to persist - Records are saved correctly
- Delete the
conversation.invitees
anduser.invitedConversations
in the Firebase console for testing to simulate activity on the records - My app sometimes shows me
conversation.invitees
anduser.invitedConversations
are empty (which is correct) or sometimes shows me they are not empty (which is not correct) – both scenarios have occurred while testing - In either case, calling
saveInvitees
again does not persist any changes on save
Expected behavior
When I make changes in the Firebase console, the many-to-many relationships in my app should refresh to reflect the current state, which would allow me to save new relationship changes
Actual behavior
Relationship data is only saved the first time (after I’ve refreshed the page, called addInvitee
, then saveInvitees
). Once I manually delete conversation.invitees
and user.invitedConversations
in the Firebase console (basically resetting my state), nothing is being persisted from my app when I call saveInvitees
again (which calls save
on each record). My guess is the dirty many-to-many relationships are causing confusion.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top GitHub Comments
Thanks for all the info @jarrodz I was planning on digging in on some of this, but still catching up from the xmas vaca backlog. I’ll see if I can repro what you’re seeing and either squash some bugs or give you a work around.
@jamesdaniels Thank you, much appreciated