Created
February 3, 2013 08:03
-
-
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.
This file contains hidden or 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
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