Skip to content

Instantly share code, notes, and snippets.

@olivia
Last active August 29, 2015 14:07
Show Gist options
  • Save olivia/cff364b1eb26da5ed2aa to your computer and use it in GitHub Desktop.
Save olivia/cff364b1eb26da5ed2aa to your computer and use it in GitHub Desktop.
Ember Data Notes

Ember Data Adapters and Serializers

General Adapter Logic

  • Calling a find with 1 argument returns a record array (identity map)
  • Ajax Errors will cause the failure callback to execute
  • Created records exist in the record array returned by all
  • data returned from commit will overwrite record data -- This happens for model data which is an update -- Can also add new models by updating relationships and sideloading data
  • meta object in payload allows you to store type specific data
  • buildURL can make nested relationship calls (/posts/:post_id/comments/:comment_id)
  • groupRecordsForFindMany can split find calls
  • Look at DS.InvalidError
  • Unload records
  • Polymorphic records are possible
  • custom transformation
  • inflection

General Serializer Logic

  • different serializers can be defined for different models
  • extending a serializer with the attrs hash, let’s you define an attribute mapping

REST Adapter Logic

  • A find for CatBug triggers a GET to the url: /cat_bugs/
  • A find for CatBug with id 1 triggers a GET to the url: /cat_bugs/1
  • The response payloads for these GETS can be either -- An single model {catBug: {..}} -- Multiple models {catBugs: [...]} -- including sideloaded data {catBugs: [...], posts:[...]}
  • POST, if an id is specified on the client-side, then a 200 with an empty response works
  • PUT, empty payload is a success
  • POST, sideloaded data will be added
  • PUT, sideloaded data will be added
  • DELETE, sideloaded data will be added
  • DELETE, empty is a success
  • Payload can specify how to get async relationship data using links object
  • look at findBelongsTo

Bug Fix

  • primarykey (not camelcased)
  • unlaoded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment