@@ -29,7 +29,7 @@ trait HybridRelations
29
29
public function hasOne($related, $foreignKey = null, $localKey = null)
30
30
{
31
31
// Check if it is a relation with an original model.
32
- if (! is_subclass_of($related, \MongoDB\Laravel\Eloquent\ Model::class)) {
32
+ if (! is_subclass_of($related, Model::class)) {
33
33
return parent::hasOne($related, $foreignKey, $localKey);
34
34
}
35
35
@@ -55,7 +55,7 @@ public function hasOne($related, $foreignKey = null, $localKey = null)
55
55
public function morphOne($related, $name, $type = null, $id = null, $localKey = null)
56
56
{
57
57
// Check if it is a relation with an original model.
58
- if (! is_subclass_of($related, \MongoDB\Laravel\Eloquent\ Model::class)) {
58
+ if (! is_subclass_of($related, Model::class)) {
59
59
return parent::morphOne($related, $name, $type, $id, $localKey);
60
60
}
61
61
@@ -79,7 +79,7 @@ public function morphOne($related, $name, $type = null, $id = null, $localKey =
79
79
public function hasMany($related, $foreignKey = null, $localKey = null)
80
80
{
81
81
// Check if it is a relation with an original model.
82
- if (! is_subclass_of($related, \MongoDB\Laravel\Eloquent\ Model::class)) {
82
+ if (! is_subclass_of($related, Model::class)) {
83
83
return parent::hasMany($related, $foreignKey, $localKey);
84
84
}
85
85
@@ -105,7 +105,7 @@ public function hasMany($related, $foreignKey = null, $localKey = null)
105
105
public function morphMany($related, $name, $type = null, $id = null, $localKey = null)
106
106
{
107
107
// Check if it is a relation with an original model.
108
- if (! is_subclass_of($related, \MongoDB\Laravel\Eloquent\ Model::class)) {
108
+ if (! is_subclass_of($related, Model::class)) {
109
109
return parent::morphMany($related, $name, $type, $id, $localKey);
110
110
}
111
111
@@ -142,7 +142,7 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat
142
142
}
143
143
144
144
// Check if it is a relation with an original model.
145
- if (! is_subclass_of($related, \MongoDB\Laravel\Eloquent\ Model::class)) {
145
+ if (! is_subclass_of($related, Model::class)) {
146
146
return parent::belongsTo($related, $foreignKey, $otherKey, $relation);
147
147
}
148
148
@@ -211,13 +211,13 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null
211
211
/**
212
212
* Define a many-to-many relationship.
213
213
*
214
- * @param string $related
215
- * @param string $collection
216
- * @param string $foreignKey
217
- * @param string $otherKey
218
- * @param string $parentKey
219
- * @param string $relatedKey
220
- * @param string $relation
214
+ * @param class- string<\Illuminate\Database\Eloquent\Model> $related
215
+ * @param string|null $collection
216
+ * @param string|null $foreignKey
217
+ * @param string|null $otherKey
218
+ * @param string|null $parentKey
219
+ * @param string|null $relatedKey
220
+ * @param string|null $relation
221
221
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
222
222
*/
223
223
public function belongsToMany(
@@ -237,7 +237,7 @@ public function belongsToMany(
237
237
}
238
238
239
239
// Check if it is a relation with an original model.
240
- if (! is_subclass_of($related, \MongoDB\Laravel\Eloquent\ Model::class)) {
240
+ if (! is_subclass_of($related, Model::class)) {
241
241
return parent::belongsToMany(
242
242
$related,
243
243
$collection,
@@ -249,13 +249,18 @@ public function belongsToMany(
249
249
);
250
250
}
251
251
252
+
252
253
// First, we'll need to determine the foreign key and "other key" for the
253
254
// relationship. Once we have determined the keys we'll make the query
254
255
// instances as well as the relationship instances we need for this.
255
256
$foreignKey = $foreignKey ?: $this->getForeignKey().'s';
256
257
257
258
$instance = new $related;
258
259
260
+ if ($otherKey === $relation) {
261
+ throw new \LogicException(sprintf('In %s::%s(), the key cannot be identical to the relation name "%s". The default key is "%s".', static::class, $relation, $relation, $instance->getForeignKey().'s'));
262
+ }
263
+
259
264
$otherKey = $otherKey ?: $instance->getForeignKey().'s';
260
265
261
266
// If no table name was provided, we can guess it by concatenating the two
@@ -301,7 +306,7 @@ protected function guessBelongsToManyRelation()
301
306
*/
302
307
public function newEloquentBuilder($query)
303
308
{
304
- if (is_subclass_of($this, \MongoDB\Laravel\Eloquent\ Model::class)) {
309
+ if (is_subclass_of($this, Model::class)) {
305
310
return new Builder($query);
306
311
}
307
312
0 commit comments