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.
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.
Most helpful comment
You can treat the
subkey as theidby doing the following:Note that it will act like an
idso it should be unique.