Skip to content

Commit

Permalink
Use static methods to create a Sort object
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jan 27, 2021
1 parent 7f8fa32 commit c12fb66
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/en/entity-reader.md
Expand Up @@ -86,7 +86,7 @@ Now we'll query for 20 latest published articles, then for 20 first articles.
$lastPublicReader = $articles->withLimit(20);

// Ordering is specified with Sort object:
$sort = (new \Yiisoft\Data\Reader\Sort(['published_at']))->withOrder(['published_at' => 'desc']);
$sort = \Yiisoft\Data\Reader\Sort::any()->withOrder(['published_at' => 'desc']);
// Note that EntityReader would not check Sort field correctness.
// Specifying non-existing fields would result in an error in Cycle code

Expand Down Expand Up @@ -136,7 +136,7 @@ class ArticleRepository extends \Cycle\ORM\Select\Repository
*/
public function findPublic(): DataReaderInterface
{
$sort = (new Sort(['published_at']))->withOrder(['published_at' => 'desc']);
$sort = Sort::any()->withOrder(['published_at' => 'desc']);
return (new EntityReader($this->select()->where(['public' => true])))->withSort($sort);
}
}
Expand All @@ -149,7 +149,7 @@ function index(ArticleRepository $repository)
// Getting EntityReader
->findPublic()
// Applying new sorting
->withSort((new Sort(['published_at']))->withOrder(['published_at' => 'asc']));
->withSort(Sort::any()->withOrder(['published_at' => 'asc']));
}
```
You may refine query conditions with filters. This filtering conditions are adding to original select query conditions, but NOT replace them.
Expand Down
6 changes: 3 additions & 3 deletions docs/ru/entity-reader.md
Expand Up @@ -90,7 +90,7 @@ foreach ($paginator->read() as $article) {
$lastPublicReader = $articles->withLimit(20);

// Правила сортировки описываются в объекте класса Sort:
$sort = (new \Yiisoft\Data\Reader\Sort(['published_at']))->withOrder(['published_at' => 'desc']);
$sort = \Yiisoft\Data\Reader\Sort::any()->withOrder(['published_at' => 'desc']);
// Учтите, что EntityReader НЕ БУДЕТ проверять правильность указанных в Sort полей!
// Указание несуществующих в таблице полей приведёт к ошибке в коде Cycle

Expand Down Expand Up @@ -138,7 +138,7 @@ class ArticleRepository extends \Cycle\ORM\Select\Repository
{
public function findPublic(): DataReaderInterface
{
$sort = (new Sort(['published_at']))->withOrder(['published_at' => 'desc']);
$sort = Sort::any()->withOrder(['published_at' => 'desc']);
// Параметры сортировки присваиваются объекту DataReader, а не \Cycle\ORM\Select
return (new EntityReader($this->select()->where(['public' => true])))->withSort($sort);
}
Expand All @@ -152,7 +152,7 @@ function index(ArticleRepository $repository)
// Получаем объект EntityReader
->findPublic()
// Применяем новое правило сортировки
->withSort((new Sort(['published_at']))->withOrder(['published_at' => 'asc']));
->withSort(Sort::any()->withOrder(['published_at' => 'asc']));
}
```

Expand Down

0 comments on commit c12fb66

Please sign in to comment.