Akita: Just a question (Not an isssue)

Created on 18 Oct 2018  路  7Comments  路  Source: datorama/akita

Is is possible to select an entity with another field than the ID?

For instance, I have the following model:

export interface User {
  _id: ID;
  status: string;
  gender: string;
  familyName: string;
  givenName: string;
  [ ... ]
  sub: string;
  [ ... ]
  createdAt: Date;
  updatedAt: Date;
}

and I'd like to select my User by its sub (which is another ID) because it is more convenient for me.

help wanted

Most helpful comment

You can treat the sub key as the id by doing the following:

@StoreConfig({ name: '...', idKey: 'sub' })
export class ...
}

Note that it will act like an id so it should be unique.

All 7 comments

That would be a custom filtering.
I think you want selectAll().filter(). The filter operator comes from RxJs.

You can treat the sub key as the id by doing the following:

@StoreConfig({ name: '...', idKey: 'sub' })
export class ...
}

Note that it will act like an id so it should be unique.

The problem is I already use idKey for my _id field.
Can I use 2 ID for the same entity?

No. But if the sub key is also your id why you are not using it instead of _id?

The entity is first created without sub. This operation is done by a user.
After that an admin check this entity and update if it's ok by assigning a sub and others parameters.
So, I cannot use the sub as id at the beginning because it does not exist.

What is the problem using the _id? Can you explain why using sub is more convenient?

On further consideration, there is no problem using _id. Thanks for the answer.

Was this page helpful?
0 / 5 - 0 ratings