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

Problem with adapeter's findMany method

giorgosera opened this issue · comments

I have overriden the buildURL method to append a special param at the end of the url for certain models in my code.

    App.store = DS.Store.create({
        revision: REVISION,
        adapter: DS.DjangoTastypieAdapter.extend({
            serverDomain: "http://"+host,
            namespace: "api/v1",
            buildURL: function(record, suffix) {
                return this._super(record,suffix) + '?specialParam=foo'
            }
        }),
    });

However, when findMany the param is appended in the middle of the url

http://example.com/api/v1/?specialParam=foo/set/1;2/

This is because in findMany the ids are appended after buildURL is called.

    findMany: function(store, type, ids) {
    var url,
    root = this.rootForType(type);

    ids = this.serializeIds(ids);

    // FindMany array through subset of resources
    if (ids instanceof Array) {
      ids = "set/" + ids.join(";") + '/';
    }

    url += ids;
    url = this.buildURL(root);


    this.ajax(url, "GET", {
      success: function(json) {
        this.didFindMany(store, type, json);
      }
    });
  },

For this use case it would be easier for you to overwrite the ajax method in the adapter. It's not needed for this standard adapter but it would be easy to append your extra parameter to the url parameter.

You can find here the original one as a reference:
https://github.com/emberjs/data/blob/master/packages/ember-data/lib/adapters/rest_adapter.js#L564