File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 9
9
use Illuminate \Database \Eloquent \Collection ;
10
10
use Illuminate \Database \Eloquent \Model ;
11
11
use Illuminate \Database \Eloquent \Relations \BelongsTo ;
12
- use Illuminate \ Database \ Eloquent \ Relations \BelongsToMany ;
12
+ use Froiden \ RestAPI \ ExtendedRelations \BelongsToMany ;
13
13
use Illuminate \Database \Eloquent \Relations \HasMany ;
14
14
use Illuminate \Database \Eloquent \Relations \HasOne ;
15
15
use Illuminate \Database \Eloquent \Relations \Relation ;
@@ -424,7 +424,7 @@ 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 ->getQualifiedRelatedPivotKeyName ());
427
+ $ join ->on ("outer_query. " . $ q -> getRelatedKeyName () , "= " , $ q ->getQualifiedRelatedPivotKeyName ());
428
428
$ join ->on ("outer_query.whatever " , "= " , $ q ->getQualifiedForeignPivotKeyName ());
429
429
})
430
430
->setBindings (array_merge ($ q ->getQuery ()->getBindings (), $ outerQuery ->getBindings ()))
@@ -870,4 +870,4 @@ protected function setQuery($query) {
870
870
}
871
871
872
872
//endregion
873
- }
873
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: Raj Kumar
5
+ * Date: 2/12/19
6
+ * Time: 5:08 PM
7
+ */
8
+
9
+ namespace Froiden \RestAPI \ExtendedRelations ;
10
+
11
+
12
+ use Illuminate \Database \Eloquent \Relations \BelongsToMany as LaravelBelongsToMany ;
13
+
14
+ class BelongsToMany extends LaravelBelongsToMany
15
+ {
16
+ /**
17
+ * @return string
18
+ */
19
+ public function getRelatedKeyName () {
20
+ return $ this ->relatedKey ?: 'id ' ;
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments