Skip to content

Instantly share code, notes, and snippets.

@kdiogenes
Created February 11, 2014 19:49
Show Gist options
  • Save kdiogenes/8942718 to your computer and use it in GitHub Desktop.
Save kdiogenes/8942718 to your computer and use it in GitHub Desktop.
Epf: Workaround for @session.load works with a singular resource
# 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