Skip to content

Instantly share code, notes, and snippets.

@dnegstad
Created November 21, 2014 00:56
Show Gist options
  • Save dnegstad/430733eb04ea4bd2fd19 to your computer and use it in GitHub Desktop.
Save dnegstad/430733eb04ea4bd2fd19 to your computer and use it in GitHub Desktop.
Shallow nested route Ember Data adapter
import DS from 'ember-data';
export default DS.ActiveModelAdapter.extend({
buildURL: function(type, id, record) {
if (id) {
return this._super.apply(this, arguments);
}
var parent = this.get('parent');
var path = [];
if (parent) {
var parentType = record.constructor.typeForRelationship(parent).typeKey;
var prefix = this.urlPrefix();
var host = this.get('host');
path.push(this.pathForType(parentType));
path.push(record.get(parent + '.id'));
path.push(this.pathForType(type));
if (prefix) { path.unshift(prefix); }
path = path.join('/');
if (!host && path) { path = '/' + path; }
return path;
} else {
return this._super.apply(this, arguments);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment