Wrong example for extractArray in source code? #1743

Closed
gonvaled opened this Issue Feb 12, 2014 · 3 comments

Comments

Projects
None yet
3 participants

As taken from the json serializer source

App.ProductsSerializer = DS.JSONSerializer.extend({
  extractArray: function(store, type, payload) {
    return payload.map(function(json) {
      return this.extractSingle(json);
    }, this);
  }
});

Error while loading route: TypeError: Object #<Object> has no method 'map'

The payload is an object:

{
     'products' : [
        { '_id' : 'prod1', ... },
        { '_id' : 'prod1', ... },
        ...
    ]
}

Also, extractSingle signature is:

extractSingle: function(store, type, payload, id, requestType) { ... }

And not:

extractSingle: function(payload) { ... }

Contributor

intuitivepixel commented Feb 12, 2014

@gonvaled, try payload.products, because products is the array and has .map, payload is just the wrapper object which does not have .map.

Hope it helps

Thanks. I already arrived to that conclusion. It is very frustrating that not even a little thing from the migration suggestions / tips are working out of the box. And mind you that I am migrating from a fully working ember application based on ember-data 0.0.14. There are so many breaking changes! For example, right now I start to think that a single object is expected on the top level, like:

{ 'id' : 'product1', ... }

Whereas I am quite certain (since the app is working and my api is doing exactly this), that before ember-data expected:

{ 'product' : { 'id' : 'product1' , ... } }

Why so many unnecessary changes!?!? Already two days migrating, and not even half-way through (and I am counting just the time invested in this round, since I have already tried this migration a couple of times)

@gonvaled gonvaled closed this Feb 12, 2014

Contributor

sly7-7 commented Feb 13, 2014

@gonvaled I understand your frustration here, I was myself migrating from 0.13 to 1.0.0, and including the tests it took me about 5 days to migrate.
Anyway, that's why now, I upgrade ember-data as soon as possible.
I don't know when the 1.0 will be released, with the same cycle and backward compatibility as ember.js, but definitely when this time will come, I'm almost sure the life with ember-data will be easier.

That beeing said, I think you point a bug in the inline documentation, concerning the extractSingle signature.

sly7-7 added a commit to sly7-7/data that referenced this issue Feb 13, 2014

[DOC] Fix extractArray
It makes the use of extractSingle consistent with the signature see #1743

As a side note I realize the store is not used in the extractSingle function, but I guess it could be usefull for people overriding it ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment