Skip to content

Instantly share code, notes, and snippets.

@danshultz
Created February 19, 2015 20:33
Show Gist options
  • Save danshultz/546e5a9d1e488f44599e to your computer and use it in GitHub Desktop.
Save danshultz/546e5a9d1e488f44599e to your computer and use it in GitHub Desktop.
Nested Url Support - Ember Data
import Ember from 'ember';
export default DS.ActiveModelAdapter.extend({
findQuery: function(store, type, query) {
// wrap the query in an Ember.Object and pass it through as the "record" to the buildUrl method
var url = this.buildURL(type.typeKey, null, Ember.Object.create(query));
return this.ajax(url, 'GET', { data: query });
},
// Goal being to have a regex manage this portion and create a declarative style to manage this
_replaceParts: function (url, id, record) {
return url;
},
pathForType: function (type) {
return this.get('urlTemplate') || this._super.apply(this, arguments);
},
buildURL: function (type, id, record) {
var url = this._super.apply(this, arguments);
return this._replaceParts(url, id, record);
}
});
import Ember from 'ember';
import ApplicationAdapter from './application';
export default ApplicationAdapter.extend({
urlTemplate: 'some/:relatedId/foo',
_replaceParts: function (url, id, record) {
return url.replace(':relatedId', record.get('relatedId'));
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment