Hey friends,
Hoping someone can help spot the issue I’m having or maybe point me in the right direction. In my app, we use a repository pattern to alter the namespace for certain requests. An example would be when we want to make a request to https://apiserver.com/v1/users/:id/workspaces
. By default my adapter namespace is set to v1
. Prior to sending the request with ember-data, I append users/:id
to the namespace of the adapter, then send the request with store.find('workspace')
. Up until ember-data 1.0.0-beta.15, this approach has worked swimmingly. I find that after upgrading to beta-16.1
that the namespace alteration isn’t picked up by the buildURL method, or I suppose it occurs after buildURL is run.
- Is it possible that this has anything to do with the Snapshot API?
- With the new injection method in initializers, could that have anything to do with it? I’m not doing any
container.lookup
in the initializer, so this may be a non-issue.
// repositories/workspace.js
appendResources: function () {
this.clearAppendedResources();
var adapterNamespace = this.get('adapter.namespace'), // We're injecting the adapter into repositories
prefix = [adapterNamespace];
if (arguments.length) {
// For each argument, lookup the related id. Push both to the namespace
for (var i=0; i < arguments.length; i++) {
prefix.push(arguments[i]);
}
this.set('adapter.namespace', prefix.join('/'));
}
},
// The method that ties it all together
getWorkspacesByUser: function (user_id, params) {
var self = this;
if (params === undefined) {
params = {};
}
this.appendResources('users', user_id); // We alter the namespace here
this.setupIncludes(); // We append some ?include=yadayada params here
// Make the request! Should be to /v1/users/:id/workspaces
return this.store.find('workspace', params).finally(function () {
// Clean up all the things
self.clearIncludes();
self.clearAppendedResources();
});
}
Here’s how we’re building the URL in the adapter for reference:
// adapters/workspace.js
buildURL: function(type, id, snapshot) {
var url = this._super(type, id, snapshot);
return this.buildIncludeURL(url);
},
buildIncludeURL: function (url) {
if (this.includes.length) {
url += '?include=' + this.includes.join(',');
}
return url;
}