question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Persistence is unreliable

See original GitHub issue
e.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

  1. With both conversation.invitees and user.invitedConversations empty, I call addInvitee to add a dirty many-to-many relationship
  2. Call saveInvitees to persist
  3. Records are saved correctly
  4. Delete the conversation.invitees and user.invitedConversations in the Firebase console for testing to simulate activity on the records
  5. My app sometimes shows me conversation.invitees and user.invitedConversations are empty (which is correct) or sometimes shows me they are not empty (which is not correct) – both scenarios have occurred while testing
  6. 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jamesdanielscommented, Jan 25, 2017

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.

0reactions
jarrodzimmcommented, Jan 26, 2017

@jamesdaniels Thank you, much appreciated

Read more comments on GitHub >

github_iconTop Results From Across the Web

The pitfalls of persistence. Why your brain makes ... - Medium
Why your brain makes bad decisions sometimes. Try and try till you succeed may not always be the best advice. (Photo credit: Raeesa...
Read more >
When can persistence be negative? - Dr. Lillian Esses
Recently, therapists have coined an interesting term, “negative persistence”. Needless to say, it refers to situations where a person keeps ...
Read more >
When Persistence Can Be Perilous - Forbes
Believing that persistence always pays dividends, they doggedly try to get good results ... But there are more bad ideas than great ones....
Read more >
Is persistence a good or bad character trait? - Quora
Persistence is neither good nor bad. Persistence is a causal reason for many instances that can attribute a progressive, myriad cause.
Read more >
The Negative Aspects Of Persistence - 990 Words | 123 Help Me
There is evidence that persistence can lead to hatred, death, and failure in life. To begin, persistence can lead to the hatred of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found