You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tests/Integration/DatabaseEloquentSubqueriesCrossDatabaseTest.php
+59Lines changed: 59 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -178,6 +178,65 @@ public function testWhereDoesntHaveAcrossDatabaseConnection()
178
178
});
179
179
$this->assertEquals('select * from "users" where not exists (select * from "posts" where "users"."id" = "posts"."user_id" and "name" like ?)', $query->toSql());
$query = UserMysql::withCount(['orders' => function ($query) {
186
+
$query->where('name', 'like', '%a%');
187
+
}
188
+
]);
189
+
$this->assertEquals('select `users`.*, (select count(*) from `mysql2`.`orders` where `users`.`id` = `orders`.`user_id` and `name` like ?) as `orders_count` from `users`', $query->toSql());
190
+
191
+
// Test MySQL same database subquery
192
+
$query = UserMysql::withCount(['posts' => function ($query) {
193
+
$query->where('name', 'like', '%a%');
194
+
}
195
+
]);
196
+
$this->assertEquals('select `users`.*, (select count(*) from `posts` where `users`.`id` = `posts`.`user_id` and `name` like ?) as `posts_count` from `users`', $query->toSql());
197
+
198
+
// Test PostgreSQL cross database subquery
199
+
$query = UserPgsql::withCount(['orders' => function ($query) {
200
+
$query->where('name', 'like', '%a%');
201
+
}
202
+
]);
203
+
$this->assertEquals('select "users".*, (select count(*) from "pgsql2"."orders" where "users"."id" = "orders"."user_id" and "name" like ?) as "orders_count" from "users"', $query->toSql());
204
+
205
+
// Test PostgreSQL same database subquery
206
+
$query = UserPgsql::withCount(['posts' => function ($query) {
207
+
$query->where('name', 'like', '%a%');
208
+
}
209
+
]);
210
+
$this->assertEquals('select "users".*, (select count(*) from "posts" where "users"."id" = "posts"."user_id" and "name" like ?) as "posts_count" from "users"', $query->toSql());
211
+
212
+
// Test SQL Server cross database subquery
213
+
$query = UserSqlsrv::withCount(['orders' => function ($query) {
214
+
$query->where('name', 'like', '%a%');
215
+
}
216
+
]);
217
+
$this->assertEquals('select [users].*, (select count(*) from [sqlsrv2].[orders] where [users].[id] = [orders].[user_id] and [name] like ?) as [orders_count] from [users]', $query->toSql());
218
+
219
+
// Test SQL Server same database subquery
220
+
$query = UserSqlsrv::withCount(['posts' => function ($query) {
221
+
$query->where('name', 'like', '%a%');
222
+
}
223
+
]);
224
+
$this->assertEquals('select [users].*, (select count(*) from [posts] where [users].[id] = [posts].[user_id] and [name] like ?) as [posts_count] from [users]', $query->toSql());
225
+
226
+
// Test SQL Server cross database subquery
227
+
$query = UserSqlite::withCount(['orders' => function ($query) {
228
+
$query->where('name', 'like', '%a%');
229
+
}
230
+
]);
231
+
$this->assertEquals('select "users".*, (select count(*) from "orders" where "users"."id" = "orders"."user_id" and "name" like ?) as "orders_count" from "users"', $query->toSql());
232
+
233
+
// Test SQL Server same database subquery
234
+
$query = UserSqlite::withCount(['posts' => function ($query) {
235
+
$query->where('name', 'like', '%a%');
236
+
}
237
+
]);
238
+
$this->assertEquals('select "users".*, (select count(*) from "posts" where "users"."id" = "posts"."user_id" and "name" like ?) as "posts_count" from "users"', $query->toSql());
0 commit comments