Skip to content

Commit 15930cc

Browse files
committed
Fix #3025
1 parent 66299d9 commit 15930cc

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/QueryDataTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function prepareCountQuery(): QueryBuilder
164164
$builder = clone $this->query;
165165

166166
if ($this->isComplexQuery($builder)) {
167-
$builder->select(DB::raw('1'));
167+
$builder->select(DB::raw('1 as dt_row_count'));
168168
if ($this->ignoreSelectInCountQuery || ! $this->isComplexQuery($builder)) {
169169
return $this->getConnection()
170170
->query()

tests/Unit/QueryDataTableTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public function test_complex_query_use_select_in_count()
4444
->orderBy('created_at')
4545
->select('id'),
4646
])
47-
->orderBy(DB::table('posts')->whereColumn('posts.user_id', 'users.id')->orderBy('created_at')->select('created_at')
47+
->orderBy(
48+
DB::table('posts')->whereColumn('posts.user_id', 'users.id')->orderBy('created_at')->select('created_at')
4849
)
4950
);
5051

@@ -64,7 +65,8 @@ public function test_complex_query_can_ignore_select_in_count()
6465
->orderBy('created_at')
6566
->select('id'),
6667
])
67-
->orderBy(DB::table('posts')->whereColumn('posts.user_id', 'users.id')->orderBy('created_at')->select('created_at')
68+
->orderBy(
69+
DB::table('posts')->whereColumn('posts.user_id', 'users.id')->orderBy('created_at')->select('created_at')
6870
)
6971
)->ignoreSelectsInCountQuery();
7072

@@ -134,6 +136,6 @@ public function assertQueryHasNoSelect($expected, $query)
134136
{
135137
$sql = $query->toSql();
136138

137-
$this->assertSame($expected, Str::startsWith($sql, 'select * from (select 1 from'), "'{$sql}' is not wrapped");
139+
$this->assertSame($expected, Str::startsWith($sql, 'select * from (select 1 as dt_row_count from'), "'{$sql}' is not wrapped");
138140
}
139141
}

0 commit comments

Comments
 (0)