Skip to content

Commit 4a6c8b4

Browse files
authored
Fix offset being specified without limit and without pagination (#176)
1 parent 277b095 commit 4a6c8b4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Entries/EntryQueryBuilder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public function find($id, $columns = ['*'])
6262

6363
public function get($columns = ['*'])
6464
{
65+
$query = $this->builder->getQuery();
66+
if ($query->offset && ! $query->limit) {
67+
$query->limit = PHP_INT_MAX;
68+
}
69+
6570
$this->addTaxonomyWheres();
6671

6772
return parent::get($columns);

tests/Data/Entries/EntryQueryBuilderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,21 @@ public function entries_are_found_using_offset()
689689
$this->assertEquals(['Post 2', 'Post 3'], $entries->map->title->all());
690690
}
691691

692+
/** @test */
693+
public function entries_are_found_using_offset_but_no_limit()
694+
{
695+
$this->createDummyCollectionAndEntries();
696+
697+
$entries = Entry::query()->get();
698+
$this->assertCount(3, $entries);
699+
$this->assertEquals(['Post 1', 'Post 2', 'Post 3'], $entries->map->title->all());
700+
701+
$entries = Entry::query()->offset(1)->get();
702+
703+
$this->assertCount(2, $entries);
704+
$this->assertEquals(['Post 2', 'Post 3'], $entries->map->title->all());
705+
}
706+
692707
/** @test */
693708
public function entries_can_be_retrieved_on_join_table_conditions()
694709
{

0 commit comments

Comments
 (0)