Created
February 11, 2014 19:49
-
-
Save kdiogenes/8942718 to your computer and use it in GitHub Desktop.
Epf: Workaround for @session.load works with a singular resource
This file contains 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
# If you have a singular resource, with this code, you can write the following | |
# to get your resource: @session.load(MyModel, 'singular') | |
# I don't like the 'singular' as an ID and prefer how RoR differentiate between | |
# singular and multiple resources, but for now is what I have :) | |
Ember.Inflector.inflector.uncountable('my_model') | |
get = Ember.get | |
Ep.RestAdapter.reopen | |
buildURL: (record, suffix) -> | |
if (suffix == 'singular') | |
@_super(record) | |
else | |
@_super.apply(@, arguments) | |
didReceiveDataForLoad: (data, type, id) -> | |
if (id == 'singular') | |
result = null | |
@processData(data, (model) -> | |
if (model.hasType(type)) | |
result = model | |
result.id = 'singular' | |
) | |
serializer = get(@, 'serializer') | |
return serializer.setMeta(data, result) | |
else | |
@_super.apply(@, arguments) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment