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

multiple requests hasMany relationship #71

Open
ghost opened this issue May 12, 2015 · 2 comments
Open

multiple requests hasMany relationship #71

ghost opened this issue May 12, 2015 · 2 comments
Labels

Comments

@ghost
Copy link

ghost commented May 12, 2015

I simplified code to show relevant issue.

Ember data models:

var page = DS.Model.extend({
    categories: DS.hasMany('category', {async: true}),
});

var category= DS.Model.extend({
    page: DS.belongsTo('page', {async: true})
});

In Parse I have relevant columns:

I have page pointer type from category -> page
I have categories array of category objectId's on each page.

When I have instance of page and try this method:

page.get('categories')

or call (in template to iterate):

page.categories

Parse data adapter makes individual GET requests for each categories.
ie: say for example Page has categories array set as ["dyutrdf23", "44fdfdf"]
will make two requests to get the categories.

I modified model hook on Categories route to make one request to fetch all page categories:

    var page = this.modelFor('page');
    return this.store.find('category', {
        where: {
            page: {
            "__type":  "Pointer",
            "className": "Page",
            "objectId": page.get('id')
            }
        }
    });

This works, I used it from https://github.com/clintjhill/ember-parse-adapter/blob/master/addon/adapters/application.js#L130.

However, I don't understand why this method (findHasMany) is not being called (for one request with query as opposed to individual requests) when I make the page.get('categories').

Maybe I've overlooked something with Ember data/Ember parse adapter here.

Any feedback appreciated. Thank you.

@ghost ghost changed the title Two requests BelongsTo multiple requests hasMany relationship May 12, 2015
@joshfester
Copy link

I can confirm that hasMany relationships have never worked for me either. Currently I just use custom queries instead of a relationship

@ghost
Copy link
Author

ghost commented May 12, 2015

Thanks.

@clintjhill clintjhill added the bug label May 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants