Composite primary keys


Is it possible to use ember-data with ?

I’m modelling a tennis match and for games the setNr and GameNr represent a unique game always. Some goes for sets, a Setnr and a GameId would always be unique.

Not a big deal if it’s not possible but it would make my database schema little cleaner :slight_smile:

I think you could create a serializer that handles that for you. Unless I’m misunderstanding, Ember data doesn’t have to know what a composite key is — it just needs to know how to deserialize it, correct? If so, the extractId hook might be the ticket.

Here’s how you might implement:

// serializers/composite-key.js
export default DS.JSONAPISerializer.extend({
  compositeKeys: ['setNr', 'GameNr'],

  exractId(modelClass, resourceHash) {
    return => resourceHash.attributes[key]).join('-');

Interesting, thanks! i’m gonna try that out and report back here.