8000 Allow a getter property to be used as a key · Issue #392 · js-data/js-data · GitHub
[go: up one dir, main page]

Skip to content
Allow a getter property to be used as a key #392
Open
@SystemParadox

Description

@SystemParadox

It seems that js-data does not support compound primary keys. #116 is marked as wontfix.

However, in #78, it is observed that you can create a computed property and use that as the key:

var SongModel = DS.defineResource({
  name: 'song',
  idAttribute: 'compoundId',
  computed: {
    compoundId: ['albumID', 'trackNumber', function (albumID, trackNumber) {
      return '' + albumID + '_' + trackNumber
    }]
  }
});

However, this does not currently work with getter properties:

var SongModel = DS.defineResource({
  name: 'song',
  idAttribute: 'compoundId',
  computed: {
    compoundId: {
      get: function () {
        return this.albumID + '_' + this.trackNumber
      }
    }]
  }
});

Results in TypeError: Cannot read property 'apply' of undefined. This is because it's assuming an array of [field1, field2, func].

Is this something that might be possible to implement?

This would allow the compoundId to be marked as enumerable: false, which would prevent it from being sent over the wire unnecessarily.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0