Search code examples
ember.jsember-dataember-cli

Metadata as parameter in route


I have my playload serialized:

count:949
next:null
previous:null
results: Array(949)
[0 … 99]
[100 … 199]
[200 … 299]
[300 … 399]
[400 … 499]
[500 … 599]
[600 … 699]
[700 … 799]
[800 … 899]
[900 … 948]
length: 949

The url parameters is limit and offset. As default it's display 20 records each, like http://localhost/data?limit=20. My router is this.store.query('model', {limit:949}); to return all data that i need, but if new records are added i have to change the limit value and this is not good.

Is there a way to pass the "meta: count" as query parameter in
this.store.query('model', {limit: meta:count}); to return all data? Or


Solution

  • I can't test this, since I don't have access to the API you are consuming, but I would try something like this:

    import { get } from '@ember/object';
    import Route from '@ember/routing/route';
    
    export default Route.extend({
    
      model() {
    
        return get(this, 'store').query('modelName', {}).then(results => {
    
          const { count } = get(results, 'meta');
    
          return get(this, 'store').query('modelName', { limit: count });
    
        });
    
      },
    
    });