getoutreach / epf

A framework for keeping your Ember.js apps in sync.
http://epf.io
MIT License
369 stars 33 forks source link

How to use '_id' as the primary key instead of 'id' #82

Closed distracteddev closed 10 years ago

distracteddev commented 11 years ago

I've looked everywhere in the RestAdapter and Serializer code and even after following the documented method for setting a primary key at https://github.com/GroupTalent/epf/blob/master/lib/serializer/serializer.js#L85

it still doesn't work :(

ghempton commented 10 years ago

I am going to create a guide for custom serialization soon. If you are using the latest version of EPF (more recent than this issue), it should be as simple as:

    App.PostSerializer = Epf.JsonSerializer.extend({
      properties: {
        id: {
          key: '_id'
        }
      }
    });

Going to close the issue, but please reopen if you are still having issues.

jasonkriss commented 10 years ago

@ghempton I'm currently updating my app to the latest version of EPF and am running into some issues here. I'll dig down further once I find some time but the issue seems to stem from the fact the model-specific serializers are not being used on deserialization.

Given your example above, upon receiving post data from the server, the RestAdapter never calls serializerFor. Thus, when JsonSerializer#keyFor calls configFor, it looks up properties directly on JsonSerializer as opposed to PostSerializer, and returns undefined rather than '_id' as it should.

I apologize for the lack of detail. I'll put together a failing test as soon as I can get some time. Just wanted to bring this to your attention first in case I am misunderstanding the way the new serializers work.