Skip to content

Commit e8f390a

Browse files
committed
Remove getHasCompareKey
Introduced by #1195
1 parent eba001a commit e8f390a

File tree

7 files changed

+3
-59
lines changed

7 files changed

+3
-59
lines changed

src/Eloquent/HybridRelations.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
use function debug_backtrace;
2020
use function is_subclass_of;
21-
use function method_exists;
2221

2322
use const DEBUG_BACKTRACE_IGNORE_ARGS;
2423

src/Helpers/QueriesRelationships.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use function in_array;
2323
use function is_array;
2424
use function is_string;
25-
use function method_exists;
2625
use function strpos;
2726

2827
trait QueriesRelationships
@@ -114,23 +113,14 @@ public function addHybridHas(Relation $relation, $operator = '>=', $count = 1, $
114113
$not = ! $not;
115114
}
116115

117-
$relations = $hasQuery->pluck($this->getHasCompareKey($relation));
116+
$key = $relation instanceof HasOneOrMany ? $relation->getForeignKeyName() : $relation->getOwnerKeyName();
117+
$relations = $hasQuery->pluck($key);
118118

119119
$relatedIds = $this->getConstrainedRelatedIds($relations, $operator, $count);
120120

121121
return $this->whereIn($this->getRelatedConstraintKey($relation), $relatedIds, $boolean, $not);
122122
}
123123

124-
/** @return string */
125-
protected function getHasCompareKey(Relation $relation)
126-
{
127-
if (method_exists($relation, 'getHasCompareKey')) {
128-
return $relation->getHasCompareKey();
129-
}
130-
131-
return $relation instanceof HasOneOrMany ? $relation->getForeignKeyName() : $relation->getOwnerKeyName();
132-
}
133-
134124
/**
135125
* @param Collection $relations
136126
* @param string $operator

src/Relations/BelongsTo.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,8 @@
77
use Illuminate\Database\Eloquent\Builder;
88
use Illuminate\Database\Eloquent\Model;
99

10-
use function property_exists;
11-
1210
class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo
1311
{
14-
/**
15-
* Get the key for comparing against the parent key in "has" query.
16-
*
17-
* @return string
18-
*/
19-
public function getHasCompareKey()
20-
{
21-
return $this->ownerKey;
22-
}
23-
2412
/** @inheritdoc */
2513
public function addConstraints()
2614
{

src/Relations/BelongsToMany.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,9 @@
1818
use function count;
1919
use function is_array;
2020
use function is_numeric;
21-
use function property_exists;
2221

2322
class BelongsToMany extends EloquentBelongsToMany
2423
{
25-
/**
26-
* Get the key for comparing against the parent key in "has" query.
27-
*
28-
* @return string
29-
*/
30-
public function getHasCompareKey()
31-
{
32-
return $this->getForeignKey();
33-
}
34-
3524
/** @inheritdoc */
3625
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
3726
{

src/Relations/HasMany.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,10 @@ public function getForeignKeyName()
2020
return $this->foreignKey;
2121
}
2222

23-
/**
24-
* Get the key for comparing against the parent key in "has" query.
25-
*
26-
* @return string
27-
*/
28-
public function getHasCompareKey()
29-
{
30-
return $this->getForeignKeyName();
31-
}
32-
3323
/** @inheritdoc */
3424
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
3525
{
36-
$foreignKey = $this->getHasCompareKey();
26+
$foreignKey = $this->getForeignKeyName();
3727

3828
return $query->select($foreignKey)->where($foreignKey, 'exists', true);
3929
}

src/Relations/HasOne.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ public function getForeignKeyName()
2020
return $this->foreignKey;
2121
}
2222

23-
/**
24-
* Get the key for comparing against the parent key in "has" query.
25-
*
26-
* @return string
27-
*/
28-
public function getHasCompareKey()
29-
{
30-
return $this->getForeignKeyName();
31-
}
32-
3323
/** @inheritdoc */
3424
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
3525
{

src/Relations/MorphTo.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use Illuminate\Database\Eloquent\Model;
88
use Illuminate\Database\Eloquent\Relations\MorphTo as EloquentMorphTo;
99

10-
use function property_exists;
11-
1210
class MorphTo extends EloquentMorphTo
1311
{
1412
/** @inheritdoc */

0 commit comments

Comments
 (0)