DS.Adapter#generateIdForRecord()

generateIdForRecord (store, type, inputProperties) (String|Number)

Defined in addon/adapter.js:221

If the globally unique IDs for your records should be generated on the client, implement the generateIdForRecord() method. This method will be invoked each time you create a new record, and the value returned from it will be assigned to the record's primaryKey.

Most traditional REST-like HTTP APIs will not use this method. Instead, the ID of the record will be set by the server, and your adapter will update the store with the new ID when it calls didCreateRecord(). Only implement this method if you intend to generate record IDs on the client-side.

The generateIdForRecord() method will be invoked with the requesting store as the first parameter and the newly created record as the second parameter:

import DS from 'ember-data';
import { v4 } from 'uuid';

export default DS.Adapter.extend({
  generateIdForRecord: function(store, inputProperties) {
    return v4();
  }
});

Parameters:

store DS.Store
type DS.Model
the DS.Model class of the record
inputProperties Object
a hash of properties to set on the newly created record.

Returns:

(String|Number)
id
doc_EmberJs
2016-11-30 16:49:24
Comments
Leave a Comment

Please login to continue.