Provide a `matches` utility or document EntityComparator
Author: parisholleyCreated Nov 10, 2021Updated Oct 25, 2023
Labelsenhancement
Is your feature request related to a problem? Please describe.
I often have service methods which accept partials (eg: EntityData<Entity> or Partial<Entity>) where it may then filter a collection of those entities and run some logic. At the moment, there is no way to use the logic similar to assign (or match?), where it can auto-correct between references, ids, and whole objects. To manually build a collection.filter() command which could adequately support reading EntityData would be very verbose and may not align with how Mikro matches internally.
Describe the solution you'd like
function (em:EntityManager, criteria:EntityData<Entity>, entities:Collection<Entity>){
// in many cases we already have a full list of entities, so don't want to use the entities.match() API
const filtered = entities.filter(criteria);
}if not using a collection (say an array or other JS collection type), EM could contain a filter method
function filter(criteria:EntityData<Entity>, entities: Iterable <Entity>);Source: mikro-orm/mikro-orm