Data: json-api "links" for pagination are being set to null

Created on 20 Oct 2017  路  6Comments  路  Source: emberjs/data

EDIT: See bottom.

Today I upgraded from ember-data 2.12.1 to the latest 2.17.1beta (along with source), I am now noticing that my pagination has broken.

In the following code, res.links is null, despite the server having returned links. The only serializer file I have is the generated ApplicationSerializer that sets it to JSONAPISerializer.

    return this.get('store')
      .query(model, this.get(`pageData.${model}.opts`))
      .then((res) => {
        this._cacheQueryOpts(model, type, {}, res.links); // res.links = null
        return RSVP.resolve(res);
      })

image

I tried overriding the ApplicationSerializer.normalize() method to add a debugger and see if the links came through there and they do come through there. I'm almost certain nothing else has changed in my app but unless anyone has an idea of how it could be getting set to null then I'm assuming something in the latest version is doing it...

Thanks

EDIT1: I have gone back and confirmed that this problem began at [email protected]. Previous versions did indeed automatically include the links data for a json-api response.

EDIT2: I have pinned down the general area where it goes wrong here. links is always null there despite payload.links having a value ({next: 'v1/foo', prev: null})

Has PR

Most helpful comment

Yes, I can confirm it is in 3.0 beta. Thanks @erichonkanen!

All 6 comments

I think I've identified the source of the problem here:

https://github.com/emberjs/data/blob/master/addon/-private/system/record-arrays/adapter-populated-record-array.js#L52

@stefanpenner do you know why you are always setting links = null? It is overriding pagination links in the server response and causing this bug...

I went back and verified that by commenting out the above line, the links attribute it set properly and it fixes the bug...

export default RecordArray.extend({
  init() {
    // yes we are touching `this` before super, but ArrayProxy has a bug that requires this.
    this.set('content', this.get('content') || Ember.A());

    this._super(...arguments);
    this.query = this.query || null;
    // this.links = null; --> Why am I here???
  },

Is this released in any version yet? I'm still experiencing this issue.

@rwwagner90 I tried upgrading to 2.18 but am still seeing this issue even though the supposed fix was merged before this version was released. Is that what you're experiencing too?

Yes, I can confirm it is in 3.0 beta. Thanks @erichonkanen!

Was this page helpful?
0 / 5 - 0 ratings