Created
February 19, 2015 20:33
-
-
Save danshultz/546e5a9d1e488f44599e to your computer and use it in GitHub Desktop.
Nested Url Support - Ember Data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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