diff --git a/src/Stache/Query/QueriesEntryStatus.php b/src/Stache/Query/QueriesEntryStatus.php index e26b8f7d0a..adc26c11d8 100644 --- a/src/Stache/Query/QueriesEntryStatus.php +++ b/src/Stache/Query/QueriesEntryStatus.php @@ -29,10 +29,12 @@ private function addCollectionStatusLogicToQuery($query, $status, $collection): { $this->addCollectionWhereToStatusQuery($query, $collection->handle()); - if ($collection->futureDateBehavior() === 'public' && $collection->pastDateBehavior() === 'public') { + if (! $collection->dated() || ($collection->futureDateBehavior() === 'public' && $collection->pastDateBehavior() === 'public')) { if ($status === 'scheduled' || $status === 'expired') { $query->where('date', 'invalid'); // intentionally trigger no results. } + + return; } if ($collection->futureDateBehavior() === 'private') { diff --git a/tests/Data/Entries/EntryQueryBuilderTest.php b/tests/Data/Entries/EntryQueryBuilderTest.php index 06244c0341..ef7aaa33ef 100644 --- a/tests/Data/Entries/EntryQueryBuilderTest.php +++ b/tests/Data/Entries/EntryQueryBuilderTest.php @@ -830,6 +830,12 @@ public function it_filters_by_status($status, $expected) EntryFactory::collection('calendar')->id('calendar-past')->published(true)->date(now()->subDay())->create(); EntryFactory::collection('calendar')->id('calendar-past-draft')->published(false)->date(now()->subDay())->create(); + // Undated, but with customized date behavior. Nonsensical situation, but it can happen. + // See https://github.com/statamic/eloquent-driver/issues/288 + Collection::make('undated')->dated(false)->futureDateBehavior('private')->pastDateBehavior('private')->save(); + EntryFactory::collection('undated')->id('undated')->published(true)->create(); + EntryFactory::collection('undated')->id('undated-draft')->published(false)->create(); + $this->assertEquals($expected, Entry::query()->whereStatus($status)->get()->map->id->all()); } @@ -844,6 +850,7 @@ public static function filterByStatusProvider() 'event-past-draft', 'calendar-future-draft', 'calendar-past-draft', + 'undated-draft', ]], 'published' => ['published', [ 'page', @@ -851,6 +858,7 @@ public static function filterByStatusProvider() 'event-future', 'calendar-future', 'calendar-past', + 'undated', ]], 'scheduled' => ['scheduled', [ 'blog-future',