Skip to content

Commit

Permalink
Add initialize without parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
byjg committed Nov 11, 2024
1 parent fd3537a commit 87fa642
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function deleteByQuery(DeleteQuery $updatable): bool
* @param bool $forUpdate
* @return array
*/
public function getByFilter(string|IteratorFilter $filter, array $params = [], bool $forUpdate = false): array
public function getByFilter(string|IteratorFilter $filter, array $params = [], bool $forUpdate = false, int $page = 0, ?int $limit = null): array
{
if ($filter instanceof IteratorFilter) {
$formatter = new IteratorFilterSqlFormatter();
Expand All @@ -226,6 +226,10 @@ public function getByFilter(string|IteratorFilter $filter, array $params = [], b
$query->forUpdate();
}

if (!is_null($limit)) {
$query->limit($page, ($page + 1) * $limit);
}

return $this->getByQuery($query);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Trait/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public static function get(mixed ...$pk)
* @param IteratorFilter $filter
* @return static[]
*/
public static function filter(IteratorFilter $filter): array
public static function filter(IteratorFilter $filter, $page = 0, $limit = 50): array
{
return self::$repository->getByFilter($filter);
return self::$repository->getByFilter($filter, page: $page, limit: $limit);
}

public static function joinWith(string ...$tables): Query
Expand Down

0 comments on commit 87fa642

Please sign in to comment.