dimanche 22 septembre 2019

How to properly use metadata in Ember query?

I have been trying to implement pagination (I've tried both ember-cli-pagination and ember-simple-pagination) for my application but I've had a lot of issues. So I decided to try custom pagination and noticed that I cannot pass metadata into my query. For instance, when visiting my api at: http://jsonplaceholder.typicode.com/posts?_start=0&_limit=10, start and limit both work properly. When calling it in my route, it seems to ignore that entirely and just give me all entries. I would appreciate all insight into what I am doing wrong or how to properly implement pagination in this case.

app/adapters/post.js

import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend({
  host:'https://jsonplaceholder.typicode.com',
  pathForType(){
    return 'posts';
  }
});

app/models/post.js

import DS from 'ember-data';
const { Model } = DS;

export default Model.extend({
  user:DS.belongsTo('user'),
  title:DS.attr('string'),
  body:DS.attr('string'),
});

app/routes/post.js

import Route from '@ember/routing/route';
import { set } from '@ember/object';
import { hash } from 'rsvp';

export default Route.extend({
  model() {
    return hash({
      post: this.store.query('post', {
                start: 0,
                limit: 10
            }),
      user: this.store.findAll('user')
    });
  },

  setupController(controller, model) {
    this._super(...arguments);
    set(controller, 'posts', model.post);
    set(controller, 'users', model.user);
  }

});




Aucun commentaire:

Enregistrer un commentaire