Skip to content

Instantly share code, notes, and snippets.

@wongyouth
Created February 3, 2013 08:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wongyouth/4700909 to your computer and use it in GitHub Desktop.
Save wongyouth/4700909 to your computer and use it in GitHub Desktop.
This is a workaround for Mongoid3 and Emberjs or Backbonejs. Make `to_json` return id key the same value as _id which will be used as a primary key for ember-data.
module Mongoid
module Serialization
def serializable_hash_with_id(options = nil)
json = serializable_hash_without_id options
json['id'] = json['_id'] if json.has_key? '_id'
json
end
alias_method_chain :serializable_hash, :id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment