7
7
use Illuminate \Database \Eloquent \Concerns \HasRelationships ;
8
8
use Illuminate \Database \Eloquent \Relations \MorphOne ;
9
9
use Illuminate \Support \Str ;
10
- use MongoDB \Laravel \Eloquent \Model as MongoDBModel ;
11
10
use MongoDB \Laravel \Helpers \EloquentBuilder ;
12
11
use MongoDB \Laravel \Relations \BelongsTo ;
13
12
use MongoDB \Laravel \Relations \BelongsToMany ;
20
19
use function array_pop ;
21
20
use function debug_backtrace ;
22
21
use function implode ;
23
- use function is_subclass_of ;
24
22
use function preg_split ;
25
23
26
24
use const DEBUG_BACKTRACE_IGNORE_ARGS ;
@@ -46,7 +44,7 @@ trait HybridRelations
46
44
public function hasOne ($ related , $ foreignKey = null , $ localKey = null )
47
45
{
48
46
// Check if it is a relation with an original model.
49
- if (! is_subclass_of ($ related, MongoDBModel::class )) {
47
+ if (! Model:: isDocumentModel ($ related )) {
50
48
return parent ::hasOne ($ related , $ foreignKey , $ localKey );
51
49
}
52
50
@@ -75,7 +73,7 @@ public function hasOne($related, $foreignKey = null, $localKey = null)
75
73
public function morphOne ($ related , $ name , $ type = null , $ id = null , $ localKey = null )
76
74
{
77
75
// Check if it is a relation with an original model.
78
- if (! is_subclass_of ($ related, MongoDBModel::class )) {
76
+ if (! Model:: isDocumentModel ($ related )) {
79
77
return parent ::morphOne ($ related , $ name , $ type , $ id , $ localKey );
80
78
}
81
79
@@ -102,7 +100,7 @@ public function morphOne($related, $name, $type = null, $id = null, $localKey =
102
100
public function hasMany ($ related , $ foreignKey = null , $ localKey = null )
103
101
{
104
102
// Check if it is a relation with an original model.
105
- if (! is_subclass_of ($ related, MongoDBModel::class )) {
103
+ if (! Model:: isDocumentModel ($ related )) {
106
104
return parent ::hasMany ($ related , $ foreignKey , $ localKey );
107
105
}
108
106
@@ -131,7 +129,7 @@ public function hasMany($related, $foreignKey = null, $localKey = null)
131
129
public function morphMany ($ related , $ name , $ type = null , $ id = null , $ localKey = null )
132
130
{
133
131
// Check if it is a relation with an original model.
134
- if (! is_subclass_of ($ related, MongoDBModel::class )) {
132
+ if (! Model:: isDocumentModel ($ related )) {
135
133
return parent ::morphMany ($ related , $ name , $ type , $ id , $ localKey );
136
134
}
137
135
@@ -171,7 +169,7 @@ public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relat
171
169
}
172
170
173
171
// Check if it is a relation with an original model.
174
- if (! is_subclass_of ($ related, MongoDBModel::class )) {
172
+ if (! Model:: isDocumentModel ($ related )) {
175
173
return parent ::belongsTo ($ related , $ foreignKey , $ ownerKey , $ relation );
176
174
}
177
175
@@ -242,7 +240,7 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null
242
240
$ ownerKey ??= $ instance ->getKeyName ();
243
241
244
242
// Check if it is a relation with an original model.
245
- if (! is_subclass_of ($ instance, MongoDBModel::class )) {
243
+ if (! Model:: isDocumentModel ($ instance )) {
246
244
return parent ::morphTo ($ name , $ type , $ id , $ ownerKey );
247
245
}
248
246
@@ -288,7 +286,7 @@ public function belongsToMany(
288
286
}
289
287
290
288
// Check if it is a relation with an original model.
291
- if (! is_subclass_of ($ related, MongoDBModel::class )) {
289
+ if (! Model:: isDocumentModel ($ related )) {
292
290
return parent ::belongsToMany (
293
291
$ related ,
294
292
$ collection ,
@@ -367,7 +365,7 @@ public function morphToMany(
367
365
}
368
366
369
367
// Check if it is a relation with an original model.
370
- if (! is_subclass_of ( $ related , Model::class )) {
368
+ if (! Model::isDocumentModel ( $ related )) {
371
369
return parent ::morphToMany (
372
370
$ related ,
373
371
$ name ,
@@ -434,7 +432,7 @@ public function morphedByMany(
434
432
) {
435
433
// If the related model is an instance of eloquent model class, leave pivot keys
436
434
// as default. It's necessary for supporting hybrid relationship
437
- if (is_subclass_of ( $ related , Model::class )) {
435
+ if (Model::isDocumentModel ( $ related )) {
438
436
// For the inverse of the polymorphic many-to-many relations, we will change
439
437
// the way we determine the foreign and other keys, as it is the opposite
440
438
// of the morph-to-many method since we're figuring out these inverses.
@@ -459,7 +457,7 @@ public function morphedByMany(
459
457
/** @inheritdoc */
460
458
public function newEloquentBuilder ($ query )
461
459
{
462
- if ($ this instanceof MongoDBModel ) {
460
+ if (Model:: isDocumentModel ( $ this ) ) {
463
461
return new Builder ($ query );
464
462
}
465
463
0 commit comments