Skip to content

Commit b4d3dc1

Browse files
committed
-
1 parent 81a0fc6 commit b4d3dc1

File tree

4 files changed

+7
-16
lines changed

4 files changed

+7
-16
lines changed

src/Eloquent/EmbedsRelations.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
trait EmbedsRelations
1616
{
1717
/**
18-
* @var array{class-string<self>, bool}
18+
* @var array<class-string, array<string, bool>>
1919
*/
20-
private static array $embeddedCache = [];
20+
private static array $hasEmbeddedRelation = [];
2121

2222
/**
2323
* Define an embedded one-to-many relationship.
@@ -98,13 +98,13 @@ private function hasEmbeddedRelation(string $key): bool
9898
return false;
9999
}
100100

101-
if (isset(self::$embeddedCache[static::class][$key])) {
102-
return self::$embeddedCache[static::class][$key];
101+
if (isset(self::$hasEmbeddedRelation[static::class][$key])) {
102+
return self::$hasEmbeddedRelation[static::class][$key];
103103
}
104104

105105
$returnType = (new ReflectionMethod($this, $method))->getReturnType();
106106

107-
return self::$embeddedCache[static::class][$key] = $returnType instanceof ReflectionNamedType
107+
return self::$hasEmbeddedRelation[static::class][$key] = $returnType instanceof ReflectionNamedType
108108
&& in_array($returnType->getName(), [EmbedsOne::class, EmbedsMany::class], true);
109109
}
110110
}

src/Eloquent/HybridRelations.php

-4
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,6 @@ public function belongsToMany(
259259

260260
$instance = new $related;
261261

262-
if ($otherKey === $relation) {
263-
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'));
264-
}
265-
266262
$otherKey = $otherKey ?: $instance->getForeignKey().'s';
267263

268264
// If no table name was provided, we can guess it by concatenating the two

tests/Models/Group.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ class Group extends Eloquent
1515

1616
public function users(): BelongsToMany
1717
{
18-
return $this->belongsToMany(User::class, 'users', 'groups', 'userIds', '_id', '_id', 'users');
18+
return $this->belongsToMany(User::class, 'users', 'groupIds', 'userIds', '_id', '_id', 'users');
1919
}
2020
}

tests/Models/User.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,7 @@ public function clients()
7979

8080
public function groups()
8181
{
82-
return $this->belongsToMany(Group::class, 'groups', 'users', 'groupIds', '_id', '_id', 'groups');
83-
}
84-
85-
public function otherGroups()
86-
{
87-
return $this->belongsToMany(Group::class, 'groups', 'users', 'otherGroups', '_id', '_id', 'groups');
82+
return $this->belongsToMany(Group::class, 'groups', 'userIds', 'groupIds', '_id', '_id', 'groups');
8883
}
8984

9085
public function photos()

0 commit comments

Comments
 (0)