Hi,
Is it possible to use ember-data with GitHub - composite-primary-keys/composite_primary_keys: Composite Primary Keys support for Active Record ?
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
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 this.compositeKeys.map((key) => resourceHash.attributes[key]).join('-');
}
});
Interesting, thanks! i’m gonna try that out and report back here.