Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relationships end up in an inconsistent state #114

Open
lolmaus opened this issue Apr 20, 2015 · 3 comments
Open

Relationships end up in an inconsistent state #114

lolmaus opened this issue Apr 20, 2015 · 3 comments

Comments

@lolmaus
Copy link

lolmaus commented Apr 20, 2015

Hi!

I'm building a hierarchical todo list, using HollyApp as a good example.

My only model looks like this:

Task = DS.Model.extend
  title:    DS.attr 'string'
  position: DS.attr 'number'

  parent:   DS.belongsTo 'task', inverse: 'children'
  children: DS.hasMany   'task', inverse: 'parent'

As you can see, the model relates to itself. This lets nesting models into each one another.

The problem is that after i create a bunch of items and drag them into one another, data in local storage eventually ends up in an inconsistent state: parents do not correspond to children.

Here's my app's prototype: lolmaus/taskaparilla@bc67f44 (You need to run Ruby's bundle install in addition to bower install and npm install).

Start the app, create a handful of tasks, then drag them into one another. The app is configured to .save() on every drag. After a while of drag-and-dropping, refresh the page. You'll see that apps end up in a different order (if the order didn't change, do some more dragging and refresh again).

Here's an example of a broken local storage content:

{
  "task":{
    "records":{
      "h1ed3":{
        "id":"h1ed3",
        "title":"One",
        "position":0,
        "parent":null,
        "children":[
          "5nskn"
        ]
      },
      "mv0kq":{
        "id":"mv0kq",
        "title":"Two",
        "position":0,
        "parent":"5nskn",
        "children":[ ]
      },
      "5nskn":{
        "id":"5nskn",
        "title":"Three",
        "position":0,
        "parent":"h1ed3",
        "children":[ ]
      }
    }
  }
}

As you can see, task Three (id 5nskn) has task Two (id mv0kq) as parent, but task Two does not have task Three as a child.

This local storage content results in the following Ember Data hierarchy:

- One
  - Three
- Two

Now, if i drag Two into Three, local storage content will not change. This means that after i refresh the page, the hierarchy will revert to the previous state.

I inspected the Ember Data content with Ember Inspector and discovered that after moving Two into Three, Ember Data content is consistent. All parents correspond to children correctly.

Please confirm whether this is a legit bug.

lolmaus added a commit to lolmaus/taskaparilla that referenced this issue Apr 20, 2015
@lolmaus
Copy link
Author

lolmaus commented Apr 20, 2015

I've fixed some bugs in my prototype and added some debug console output:

lolmaus/taskaparilla@56f829f

Start from an empty list, create a number of tasks and start rearranging them while looking into browser console.

You'll see that the info (reported from iterating this.store.all()) is always correct.

But once you refresh the page, item positions are messed up as well as item parents/children.

PS I haven't implemented automatic position correction, so once ember-localstorage-adapter messes up positions, they will remain incorrect until you remove all items and start from scratch.

@kurko
Copy link
Collaborator

kurko commented Jun 12, 2015

@lolmaus unfortunately, I'm not currently in any project using LS :( did you find a fix for this?

@CrushedPixel
Copy link

After over two years, this is still an issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants