-
-
Notifications
You must be signed in to change notification settings - Fork 0
Repository API
wind111-lang edited this page Jul 9, 2026
·
1 revision
Sumire\EntityRepository provides a typed helper around Database for one entity class.
You usually create it through Database::repository().
$users = $database->repository(User::class);public function find(mixed $id): ?objectFinds one entity by primary key.
$user = $users->find(1);Returns null when no row is found.
public function findBy(
array $criteria = [],
array $orderBy = [],
?int $limit = null,
?int $offset = null,
): arrayFinds entities matching criteria.
$activeUsers = $users->findBy(
['active' => true],
['name' => 'ASC'],
limit: 20,
);public function firstBy(array $criteria = [], array $orderBy = []): ?objectReturns the first matching entity.
$ada = $users->firstBy(['email' => 'ada@example.com']);This is equivalent to findBy($criteria, $orderBy, 1)[0] ?? null.
public function all(): arrayReturns all rows for the repository entity.
$allUsers = $users->all();Use this only when the table is small or when you intentionally need all rows.
public function save(object $entity): voidPersists an entity through the repository.
$users->save($user);This delegates to Database::persist().
public function remove(object $entity): voidDeletes an entity through the repository.
$users->remove($user);This delegates to Database::remove().