Skip to content

Provide a matches utility or document EntityComparator #2392

@parisholley

Description

@parisholley

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>);

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions