Ember-data and MongoDB, how to handle _id

后端 未结 9 813
别跟我提以往
别跟我提以往 2021-02-08 17:20

I\'m using ember-data with rails and MongoDB and am having problem with the way IDs are stored in MongoDB - in a _id field.

Ember-data will use id as the default field f

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-08 17:32

    The second part of joscas's answer fixed the id issue for me with Rails4/Ruby2 except I had to .to_s the _id.

    class UserSerializer < ActiveModel::Serializer
      attributes :id, :name, :email
      def id
        object._id.to_s
      end
    end
    

提交回复
热议问题