Search
FindBy
Repositories provide a convenient method to find entities.
You can search for a specific value (we use internally the ===
operator)
// Will returns the entities where the name is exactly matching the given string
const entities = repository.findBy({
name: 'adactive'
});
You can also provide a custom filter function
// Will returns the entities where the function is true
const entities = repository.findBy({
name: (name) => {
return name === 'adactive' | name === 'adsum';
}
});
// Will returns all entities with no associated logo
const entities = repository.findBy({
logo: (reference) => {
return reference.is(null);
}
});
You can filter accross multiple properties, it will act like the &&
operator
// Will returns the entities where the type is 'person' and description is `null`
const entities = repository.findBy({
type: 'person',
description: null,
});
FindOneBy
This act is same as FindBy but will return an entity or null instead of an array.
If there are more than one result, it will throw an error