escalant3 / ember-data-tastypie-adapter

An adapter to connect django applications powered by django-tastypie with ember.js apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect extractMany implementaion

andrewfan opened this issue · comments

Your extractMany method never call extractRecordRepresentation
So for:

A = DS.Model.extend({
      b: DS.belongsTo('App.B')
})
a = A.find({limit:1})  //  {objects: [{//some_fields: b: {some_fields for B}}]}
a.objectAt(0).serialize() 

fails, because we dont have store representation for b model.

i suggest you to replace your extractMany method in serializer on:

extractMany:function (loader, json, type, records) {
    if (json.objects) {
        var objects = json.objects, references = [];
        if (records) { records = records.toArray(); }

        for (var i = 0; i < objects.length; i++) {
            if (records) { loader.updateId(records[i], objects[i]); }
            var reference = this.extractRecordRepresentation(loader, type, objects[i]);
            references.push(reference);
        }
        loader.populateArray(references);
    }
}

Thanks @andrewfan. You are right. The problem is that the current implementation of the adapter is using an obsolete version of ember-data. I cannot just apply your fix because that records fourth parameter has been added later. You can compare the version used https://github.com/escalant3/ember-data-tastypie-adapter/blob/master/tests/lib/ember-data.js#L6306 with the current oficial version https://github.com/emberjs/data/blob/master/packages/ember-data/lib/serializers/json_serializer.js#L164.

I will try to update the adapter to the latest version and then apply your patch. I have already created a failing test in this branch https://github.com/escalant3/ember-data-tastypie-adapter/tree/embedded-array-issue