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

RESTAdapter does not restore hasMany items list #2610

Closed
kgish opened this issue Dec 18, 2014 · 4 comments
Closed

RESTAdapter does not restore hasMany items list #2610

kgish opened this issue Dec 18, 2014 · 4 comments

Comments

@kgish
Copy link

kgish commented Dec 18, 2014

I believe I've discovered a serious bug in the RESTAdapter and would therefore like to report it.

Been struggling now for many days trying to figure this out, and have finally resolved the issue (I hope).

It has to do with a nested one-to-many relationship with belongs-to referring back to the parent (which is what is causing the problem, I believe).

When I remove item: DS.belongsTo('item', {async: true} ) in my App.Key model, it works!

This ONLY occurs when I have the RESTAdapter enabled and NOT when using the identical code with fixtures, e.g. using App.ApplicationAdapter = DS.FixtureAdapter.extend({});

That's why I suspect that it is a bug in the RESTAdapter unless I'm doing something wrong.

It could have something to do with my usage of this.modelFor('item').get('keys') but this works just fine with fixtures.

Here's the problem:

/folders => ok
/folders/A/items => ok
/folders/B/items => ok
/folders/A/items => nok (no keys)
/folders/B/items => ok
/folders/C/items => ok
/folders/B/items => nok (no keys)
/folders/C/items => ok
...

As you can see, only the last item route which has resulted in a REST request retains it's key list, while all other items in the list become emptied.

This only affects the items, and selecting different folders back and forth has no affect on the items lists.

This is my data model:

App.ApplicationAdapter = DS.RESTAdapter.extend({});

/** MODELS **/
App.Folder = DS.Model.extend({
    name: DS.attr('string'),
    ftype: DS.attr('string'),
    count: DS.attr('number'),
    items: DS.hasMany('item', {async: true} )
});

App.Item = DS.Model.extend({
    name: DS.attr('string'),
    folder: DS.belongsTo('folder', {async: true} ),
    count: DS.attr('number'),
    keys: DS.hasMany('key', {async: true} )
});

App.Key = DS.Model.extend({
    name: DS.attr('string'),
    value: DS.attr('string'),
    item: DS.belongsTo('item', {async: true} ) // <== REMOVE to fix
});

This is what my router map looks like:

/** ROUTER MAP **/
App.Router.map(function() {
    this.resource('folders', function() {
        this.resource('folder', { path: ':folder_id' }, function() {
            this.resource('items', function() {
                this.resource('item', { path: ':item_id' }, function() {
                    this.resource('keys', function() {});
                });
            })
        })
    });
});

Here are my routes:

App.FoldersRoute = Ember.Route.extend({
    model: function() {
        return this.store.find('folder');
    }
});

App.ItemsRoute = Ember.Route.extend({
    model: function() {
        return this.modelFor('folder').get('items');
    }
});

App.KeysRoute = Ember.Route.extend({
    model: function() {
        return this.modelFor('item').get('keys');
    }
});

Here is my configuration:

DEBUG: -------------------------------
DEBUG: Ember      : 1.8.1
DEBUG: Ember Data : 1.0.0-beta.11
DEBUG: Handlebars : 1.3.0
DEBUG: jQuery     : 1.10.2
DEBUG: -------------------------------

Details of my environment:

Google Chrome Version 39.0.2171.95 (64-bit)
Ubuntu 14.04 LTS

Thanks alot in advance for having a look. I hope that I have provided sufficient information to figure out what's wrong and fix it.

See: https://github.com/kgish/zmail-client

@bmac
Copy link
Member

bmac commented Jan 15, 2015

Hello @kgish sorry for not replying sooner.

Would it be possible to post some sample response data or a simplified test case? I tried to get the python server in the zmail-client repo running but I was unable to successfully install the MAPI dependency.

@wecc
Copy link
Contributor

wecc commented Jun 2, 2015

ping @kgish

@kgish
Copy link
Author

kgish commented Jun 2, 2015

Wow, this was quite some time ago and not sure if I remember enough to come up with a correct test demo. Perhaps I can mock the response in order to reproduce.

@wecc
Copy link
Contributor

wecc commented Sep 16, 2015

Closing due to inactivity. Feel free to re-open if you're able to reproduce and it's still a problem.

@wecc wecc closed this as completed Sep 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants