@@ -410,9 +410,9 @@ protected function addIncludes()
410
410
// to make them work
411
411
$ innerQuery = $ q ->getQuery ();
412
412
$ innerQuery ->select ($ fields );
413
- $ innerQuery ->selectRaw ("@currcount := IF(@currvalue = " . $ q ->getForeignKey () . ", @currcount + 1, 1) AS rank " );
414
- $ innerQuery ->selectRaw ("@currvalue := " . $ q ->getForeignKey () . " AS whatever " );
415
- $ innerQuery ->orderBy ($ q ->getForeignKey (), ($ relation ["order " ] == "chronological " ) ? "ASC " : "DESC " );
413
+ $ innerQuery ->selectRaw ("@currcount := IF(@currvalue = " . $ q ->getQualifiedForeignPivotKeyName () . ", @currcount + 1, 1) AS rank " );
414
+ $ innerQuery ->selectRaw ("@currvalue := " . $ q ->getQualifiedForeignPivotKeyName () . " AS whatever " );
415
+ $ innerQuery ->orderBy ($ q ->getQualifiedForeignPivotKeyName (), ($ relation ["order " ] == "chronological " ) ? "ASC " : "DESC " );
416
416
417
417
// Inner Join causes issues when a relation for parent does not exist.
418
418
// So, we change it to right join for this query
@@ -424,8 +424,8 @@ protected function addIncludes()
424
424
425
425
$ q ->select ($ fields )
426
426
->join (\DB ::raw ("( " . $ outerQuery ->toSql () . ") as `outer_query` " ), function ($ join ) use ($ q ) {
427
- $ join ->on ("outer_query.id " , "= " , $ q ->getOtherKey ());
428
- $ join ->on ("outer_query.whatever " , "= " , $ q ->getForeignKey ());
427
+ $ join ->on ("outer_query.id " , "= " , $ q ->getQualifiedRelatedPivotKeyName ());
428
+ $ join ->on ("outer_query.whatever " , "= " , $ q ->getQualifiedForeignPivotKeyName ());
429
429
})
430
430
->setBindings (array_merge ($ q ->getQuery ()->getBindings (), $ outerQuery ->getBindings ()))
431
431
->where ("rank " , "<= " , $ relation ["limit " ] + $ relation ["offset " ])
@@ -435,7 +435,7 @@ protected function addIncludes()
435
435
// We need to select foreign key so that Laravel can match to which records these
436
436
// need to be attached
437
437
if ($ q instanceof BelongsTo) {
438
- $ fields [] = $ q ->getOtherKey ();
438
+ $ fields [] = $ q ->getOwnerKey ();
439
439
440
440
if (strpos ($ key , ". " ) !== false ) {
441
441
$ parts = explode (". " , $ key );
@@ -445,15 +445,15 @@ protected function addIncludes()
445
445
}
446
446
}
447
447
else if ($ q instanceof HasOne) {
448
- $ fields [] = $ q ->getForeignKey ();
448
+ $ fields [] = $ q ->getQualifiedForeignKeyName ();
449
449
450
450
// This will be used to hide this foreign key field
451
451
// in the processAppends function later
452
- $ relations [$ key ]["foreign " ] = $ q ->getForeignKey ();
452
+ $ relations [$ key ]["foreign " ] = $ q ->getQualifiedForeignKeyName ();
453
453
}
454
454
else if ($ q instanceof HasMany) {
455
- $ fields [] = $ q ->getForeignKey ();
456
- $ relations [$ key ]["foreign " ] = $ q ->getForeignKey ();
455
+ $ fields [] = $ q ->getQualifiedForeignKeyName ();
456
+ $ relations [$ key ]["foreign " ] = $ q ->getQualifiedForeignKeyName ();
457
457
458
458
$ q ->orderBy ($ primaryKey , ($ relation ["order " ] == "chronological " ) ? "ASC " : "DESC " );
459
459
}
0 commit comments