Platform: How to manage without an "id" field, or custom "id" field?

Created on 17 Nov 2017  路  2Comments  路  Source: ngrx/platform

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Feature request
[ x] Documentation issue or request

What is the current behavior?

I have an object that has a custom id field. For example I have a "Location" object and my id field is called "locationid" instead of just "id". From all the examples and test I've ran, it looks like I need an "id" field.

Expected behavior:

How do I map my "locationid" to "id"?

Minimal reproduction of the problem with instructions:

My object

export interface Location {
locationid: number,
name: string,
address: string
}

Version of affected browser(s),operating system(s), npm, node and ngrx:

node v8.6.0
npm 5.5.1
ngrx 4.1.1

Most helpful comment

If you are talking about ngrx/entity, just specifiy a selectId method when creating your EntityAdapter.
See https://github.com/ngrx/platform/blob/master/docs/entity/adapter.md#createentityadapter

export const adapter: EntityAdapter<Location > = createEntityAdapter<Location>({
  selectId: (location: Location) => location.locationid,
});

All 2 comments

If you are talking about ngrx/entity, just specifiy a selectId method when creating your EntityAdapter.
See https://github.com/ngrx/platform/blob/master/docs/entity/adapter.md#createentityadapter

export const adapter: EntityAdapter<Location > = createEntityAdapter<Location>({
  selectId: (location: Location) => location.locationid,
});

Support questions should be handled in the support channel or stackoverflow

Was this page helpful?
0 / 5 - 0 ratings