@@ -188,17 +188,21 @@ static function (): EloquentBuilder {
188
188
' "table_alias_1"."name" as "table_alias_1_name", ' .
189
189
' "table_alias_1"."created_at" as "table_alias_1_created_at" ' .
190
190
'from "table_a" ' .
191
- 'left join "table_b" as "table_alias_0" ' .
192
- ' on "table_alias_0"."id" = "table_a"."belongs_to_b_id" ' .
193
- 'left join "table_c" as "table_alias_1" ' .
194
- ' on "table_alias_1"."id" = "table_alias_0"."belongs_to_c_id" ' .
191
+ 'left join (select * from "table_b" where "table_b"."id" = ? and "a" = ?) ' .
192
+ ' as "table_alias_0" on "table_alias_0"."id" = "table_a"."belongs_to_b_id" ' .
193
+ 'left join (select * from "table_c" where "table_c"."id" = ?) ' .
194
+ ' as "table_alias_1" on "table_alias_1"."id" = "table_alias_0"."belongs_to_c_id" ' .
195
195
'order by ' .
196
196
' "table_alias_0_name" asc, ' .
197
197
' "table_alias_0_created_at" desc, ' .
198
198
' "table_alias_1_name" desc, ' .
199
199
' "table_alias_1_created_at" desc, ' .
200
200
' "table_a"."name" asc ' ,
201
- 'bindings ' => [],
201
+ 'bindings ' => [
202
+ 34 ,
203
+ 'a ' ,
204
+ 78 ,
205
+ ],
202
206
],
203
207
static function (): EloquentBuilder {
204
208
return SortBuilderTest__ModelA::query ();
@@ -235,17 +239,23 @@ static function (): EloquentBuilder {
235
239
' "table_alias_1"."name" as "table_alias_1_name", ' .
236
240
' "table_alias_1"."created_at" as "table_alias_1_created_at" ' .
237
241
'from "table_a" ' .
238
- 'left join "table_b" as "table_alias_0" ' .
239
- ' on "table_alias_0"."model_a_id" = "table_a"."id" ' .
240
- 'left join "table_c" as "table_alias_1" ' .
241
- ' on "table_alias_1"."model_b_id" = "table_alias_0"."id" ' .
242
+ 'left join (select * from "table_b" where ' .
243
+ ' "table_b"."model_a_id" = ? and "table_b"."model_a_id" is not null and "b" = ? ' .
244
+ ') as "table_alias_0" on "table_alias_0"."model_a_id" = "table_a"."id" ' .
245
+ 'left join (select * from "table_c" where ' .
246
+ ' "table_c"."model_b_id" = ? and "table_c"."model_b_id" is not null ' .
247
+ ') as "table_alias_1" on "table_alias_1"."model_b_id" = "table_alias_0"."id" ' .
242
248
'order by ' .
243
249
' "table_alias_0_name" asc, ' .
244
250
' "table_alias_0_created_at" desc, ' .
245
251
' "table_alias_1_name" desc, ' .
246
252
' "table_alias_1_created_at" desc, ' .
247
253
' "table_a"."name" asc ' ,
248
- 'bindings ' => [],
254
+ 'bindings ' => [
255
+ 12 ,
256
+ 'b ' ,
257
+ 56 ,
258
+ ],
249
259
],
250
260
static function (): EloquentBuilder {
251
261
return SortBuilderTest__ModelA::query ();
@@ -292,12 +302,24 @@ class SortBuilderTest__ModelA extends Model {
292
302
*/
293
303
public $ table = 'table_a ' ;
294
304
305
+ public function __construct () {
306
+ self ::unguard (true );
307
+ parent ::__construct ([
308
+ $ this ->getKeyName () => 12 ,
309
+ 'belongs_to_b_id ' => 34 ,
310
+ ]);
311
+ }
312
+
295
313
public function belongsToB (): BelongsTo {
296
- return $ this ->belongsTo (SortBuilderTest__ModelB::class);
314
+ return $ this
315
+ ->belongsTo (SortBuilderTest__ModelB::class)
316
+ ->where ('a ' , '= ' , 'a ' );
297
317
}
298
318
299
319
public function hasOneB (): HasOne {
300
- return $ this ->hasOne (SortBuilderTest__ModelB::class, 'model_a_id ' );
320
+ return $ this
321
+ ->hasOne (SortBuilderTest__ModelB::class, 'model_a_id ' )
322
+ ->where ('b ' , '= ' , 'b ' );
301
323
}
302
324
303
325
public function unsupported (): HasMany {
@@ -317,6 +339,14 @@ class SortBuilderTest__ModelB extends Model {
317
339
*/
318
340
public $ table = 'table_b ' ;
319
341
342
+ public function __construct () {
343
+ self ::unguard (true );
344
+ parent ::__construct ([
345
+ $ this ->getKeyName () => 56 ,
346
+ 'belongs_to_c_id ' => 78 ,
347
+ ]);
348
+ }
349
+
320
350
public function belongsToC (): BelongsTo {
321
351
return $ this ->belongsTo (SortBuilderTest__ModelC::class);
322
352
}
@@ -337,4 +367,11 @@ class SortBuilderTest__ModelC extends Model {
337
367
* @var string
338
368
*/
339
369
public $ table = 'table_c ' ;
370
+
371
+ public function __construct () {
372
+ self ::unguard (true );
373
+ parent ::__construct ([
374
+ $ this ->getKeyName () => 90 ,
375
+ ]);
376
+ }
340
377
}
0 commit comments