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

Not working with multiple models. #193

Closed
DenimTornado opened this issue Nov 24, 2016 · 3 comments
Closed

Not working with multiple models. #193

DenimTornado opened this issue Nov 24, 2016 · 3 comments

Comments

@DenimTornado
Copy link

DenimTornado commented Nov 24, 2016

Hi, @hhff !
I have news feed. Every feed has it's comments. So i get model like that:

model(params, transition) {
    var self = this;
    var id = transition.params['news-item'].id;
    return Ember.RSVP.hash({
        current_news: self.store.findRecord('news', id),
        comments: self.infinityModel("comments", {
            perPage: 20,
            startingPage: 1,
            news_id: id
        })
    });
}

As a result - comments and this news are loaded, but there is no request for the next pages of comments, is there the way to fix it?

@hhff
Copy link
Collaborator

hhff commented Nov 24, 2016

Hi @DenimTornado - this is a super standard usecase and works great with Ember Infinity!

You'll need a modelPath attribute, because your infinityModel is now nested one layer deep in your model object.

        comments: self.infinityModel("comments", {
            perPage: 20,
            startingPage: 1,
            news_id: id,
            modelPath: 'model.comments'
        })

You'll also need to make sure you're putting the
{{#infinity-loader infinityModel=model.comments}}
In your template. When it comes into view, it should trigger a new load!

If you're continuing to have issues - please open an issue on stack overflow 👍

@hhff hhff closed this as completed Nov 24, 2016
@DenimTornado
Copy link
Author

Sorry for commenting again. Still no success.
my news-item route:

    model(params, transition) {
        var self = this;
        var id = transition.params['news-item'].id;
        return Ember.RSVP.hash({
            news_current: (function() {
                return self.store.findRecord('news', id);
            })(),
            comments: self.infinityModel("comments", {
                perPage: 20,
                startingPage: 1,
                news_id: id,
                modelPath: 'model.comments'
            })
        });
    },

my news-item template:

{{news/news-comments model=model news_id=model.news_current.id}}

my news-comments component:

import Ember from 'ember';

export default Ember.Component.extend({
infinityLoadAction: 'infinityLoad', //infinityScroll config
    actions: {
        infinityLoad(infinityModel) {
            console.log(infinityModel);
            this.sendAction('infinityLoadAction', infinityModel);
        }
    }
});

my news-comments template:

                {{#each model.comments as |comment index|}}
                    {{comment-content model=comment newsId=news_id}}
                {{/each}}

                {{#infinity-loader infinityModel=model.comments destroyOnInfinity=true}}
                    <div class="loader">
                        <img src="../social/img/ajax-loader.gif" alt="" width="24" height="24">
                    </div>
                {{/infinity-loader}}

And there is no network request from there on scroll!
What is my error? Please help me!

@DenimTornado
Copy link
Author

Ok, i got it!

The fix is:
modelPath: 'controller.model.comments'

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

2 participants