Skip to content
This repository was archived by the owner on Mar 20, 2022. It is now read-only.

Commit 5b73515

Browse files
committed
Merge branch 'atrefz-get-id-attribute'
2 parents 1594bc5 + 7f778aa commit 5b73515

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

docs/api.md

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ You *do not* need to define any keys in your entity other than those that hold n
179179

180180
* `define(definition)`: When used, the `definition` passed in will be merged with the original definition passed to the `Entity` constructor. This method tends to be useful for creating circular references in schema.
181181
* `key`: Returns the key provided to the constructor.
182+
* `idAttribute`: Returns the idAttribute provided to the constructor in options.
182183

183184
#### Usage
184185

src/__tests__/index.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ describe('normalize', () => {
113113
});
114114
expect(normalize({ user: { id: '456' } }, recommendation)).toMatchSnapshot();
115115
expect(idAttributeFn.mock.calls).toMatchSnapshot();
116+
expect(recommendation.idAttribute).toBe(idAttributeFn);
116117
});
117118

118119
it('passes over pre-normalized values', () => {

src/schemas/Entity.js

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default class EntitySchema {
1616

1717
this._key = key;
1818
this._getId = typeof idAttribute === 'function' ? idAttribute : (input) => input[idAttribute];
19+
this._idAttribute = idAttribute
1920
this._mergeStrategy = mergeStrategy;
2021
this._processStrategy = processStrategy;
2122
this.define(definition);
@@ -24,6 +25,10 @@ export default class EntitySchema {
2425
get key() {
2526
return this._key;
2627
}
28+
29+
get idAttribute() {
30+
return this._idAttribute
31+
}
2732

2833
define(definition) {
2934
this.schema = Object.keys(definition).reduce((entitySchema, key) => {

0 commit comments

Comments
 (0)