@@ -22,7 +22,7 @@ trait HybridRelations
22
22
public function hasOne ($ related , $ foreignKey = null , $ localKey = null )
23
23
{
24
24
// Check if it is a relation with an original model.
25
- if (! is_subclass_of ($ related , ' Jenssegers\Mongodb\Eloquent\Model ' )) {
25
+ if (! is_subclass_of ($ related , \ Jenssegers \Mongodb \Eloquent \Model::class )) {
26
26
return parent ::hasOne ($ related , $ foreignKey , $ localKey );
27
27
}
28
28
@@ -48,16 +48,14 @@ public function hasOne($related, $foreignKey = null, $localKey = null)
48
48
public function morphOne ($ related , $ name , $ type = null , $ id = null , $ localKey = null )
49
49
{
50
50
// Check if it is a relation with an original model.
51
- if (! is_subclass_of ($ related , ' Jenssegers\Mongodb\Eloquent\Model ' )) {
51
+ if (! is_subclass_of ($ related , \ Jenssegers \Mongodb \Eloquent \Model::class )) {
52
52
return parent ::morphOne ($ related , $ name , $ type , $ id , $ localKey );
53
53
}
54
54
55
55
$ instance = new $ related ;
56
56
57
57
list ($ type , $ id ) = $ this ->getMorphs ($ name , $ type , $ id );
58
58
59
- $ table = $ instance ->getTable ();
60
-
61
59
$ localKey = $ localKey ?: $ this ->getKeyName ();
62
60
63
61
return new MorphOne ($ instance ->newQuery (), $ this , $ type , $ id , $ localKey );
@@ -74,7 +72,7 @@ public function morphOne($related, $name, $type = null, $id = null, $localKey =
74
72
public function hasMany ($ related , $ foreignKey = null , $ localKey = null )
75
73
{
76
74
// Check if it is a relation with an original model.
77
- if (! is_subclass_of ($ related , ' Jenssegers\Mongodb\Eloquent\Model ' )) {
75
+ if (! is_subclass_of ($ related , \ Jenssegers \Mongodb \Eloquent \Model::class )) {
78
76
return parent ::hasMany ($ related , $ foreignKey , $ localKey );
79
77
}
80
78
@@ -100,7 +98,7 @@ public function hasMany($related, $foreignKey = null, $localKey = null)
100
98
public function morphMany ($ related , $ name , $ type = null , $ id = null , $ localKey = null )
101
99
{
102
100
// Check if it is a relation with an original model.
103
- if (! is_subclass_of ($ related , ' Jenssegers\Mongodb\Eloquent\Model ' )) {
101
+ if (! is_subclass_of ($ related , \ Jenssegers \Mongodb \Eloquent \Model::class )) {
104
102
return parent ::morphMany ($ related , $ name , $ type , $ id , $ localKey );
105
103
}
106
104
@@ -139,7 +137,7 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat
139
137
}
140
138
141
139
// Check if it is a relation with an original model.
142
- if (! is_subclass_of ($ related , ' Jenssegers\Mongodb\Eloquent\Model ' )) {
140
+ if (! is_subclass_of ($ related , \ Jenssegers \Mongodb \Eloquent \Model::class )) {
143
141
return parent ::belongsTo ($ related , $ foreignKey , $ otherKey , $ relation );
144
142
}
145
143
@@ -222,11 +220,11 @@ public function belongsToMany($related, $collection = null, $foreignKey = null,
222
220
// name of the calling function. We will use that function name as the
223
221
// title of this relation since that is a great convention to apply.
224
222
if (is_null ($ relation )) {
225
- $ relation = $ this ->getBelongsToManyCaller ();
223
+ $ relation = $ this ->guessBelongsToManyRelation ();
226
224
}
227
225
228
226
// Check if it is a relation with an original model.
229
- if (! is_subclass_of ($ related , ' Jenssegers\Mongodb\Eloquent\Model ' )) {
227
+ if (! is_subclass_of ($ related , \ Jenssegers \Mongodb \Eloquent \Model::class )) {
230
228
return parent ::belongsToMany ($ related , $ collection , $ foreignKey , $ otherKey , $ relation );
231
229
}
232
230
@@ -253,4 +251,18 @@ public function belongsToMany($related, $collection = null, $foreignKey = null,
253
251
254
252
return new BelongsToMany ($ query , $ this , $ collection , $ foreignKey , $ otherKey , $ relation );
255
253
}
254
+
255
+ /**
256
+ * Get the relationship name of the belongs to many.
257
+ *
258
+ * @return string
259
+ */
260
+ protected function guessBelongsToManyRelation ()
261
+ {
262
+ if (method_exists ($ this , 'getBelongsToManyCaller ' )) {
263
+ return $ this ->getBelongsToManyCaller ();
264
+ }
265
+
266
+ return parent ::guessBelongsToManyRelation ();
267
+ }
256
268
}
0 commit comments