Skip to content

Instantly share code, notes, and snippets.

@dguettler
Forked from danshultz/application.js
Last active August 29, 2015 14:15
Show Gist options
  • Save dguettler/36283bbb8eee752a86ec to your computer and use it in GitHub Desktop.
Save dguettler/36283bbb8eee752a86ec to your computer and use it in GitHub Desktop.
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