Skip to content

Instantly share code, notes, and snippets.

@richardkall
Last active December 3, 2023 22:08
Show Gist options
  • Save richardkall/5910875 to your computer and use it in GitHub Desktop.
Save richardkall/5910875 to your computer and use it in GitHub Desktop.
Ember.js REST adapter without JSON root element.
App.Adapter = DS.RESTAdapter.extend
serializer: DS.RESTSerializer.extend
extract: (loader, json, type, record) ->
root = @rootForType(type)
// Embed JSON data in a new object with root element
newJSON = {}
newJSON[root] = json
json = newJSON
//
@sideload loader, type, json, root
@extractMeta loader, type, json
if json[root]
loader.updateId record, json[root] if record
@extractRecordRepresentation loader, type, json[root]
else
Ember.Logger.warn "Extract requested, but no data given for " + type + ". This may cause weird problems."
extractMany: (loader, json, type, records) ->
root = @rootForType(type)
root = @pluralize(root)
// Embed JSON data in a new object with root element
newJSON = {}
newJSON[root] = json
json = newJSON
//
@sideload loader, type, json, root
@extractMeta loader, type, json
if json[root]
objects = json[root]
references = []
records = records.toArray() if records
i = 0
while i < objects.length
loader.updateId records[i], objects[i] if records
reference = @extractRecordRepresentation(loader, type, objects[i])
references.push reference
i++
loader.populateArray references
App.Store = DS.Store.extend
revision: 12
adapter: App.Adapter.create()
@JemiloII
Copy link

JemiloII commented Aug 1, 2014

Coffee..... eh, I guess I'll convert it to normal javascript.

@mariosant
Copy link

@JemiloII, no it's fine 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment