Skip to content

Commit 9956dc5

Browse files
authored
Remove call to getBelongsToManyCaller for compatibility with Laravel before 5.x (#2615)
laravel/framework@4ff0060 Introduced by 3e26e05 #1116
1 parent f14204f commit 9956dc5

File tree

4 files changed

+7
-59
lines changed

4 files changed

+7
-59
lines changed

src/Eloquent/HybridRelations.php

Lines changed: 0 additions & 15 deletions
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

@@ -324,20 +323,6 @@ public function belongsToMany(
324323
);
325324
}
326325

327-
/**
328-
* Get the relationship name of the belongs to many.
329-
*
330-
* @return string
331-
*/
332-
protected function guessBelongsToManyRelation()
333-
{
334-
if (method_exists($this, 'getBelongsToManyCaller')) {
335-
return $this->getBelongsToManyCaller();
336-
}
337-
338-
return parent::guessBelongsToManyRelation();
339-
}
340-
341326
/** @inheritdoc */
342327
public function newEloquentBuilder($query)
343328
{

src/Relations/BelongsTo.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
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
{
1412
/**
@@ -18,7 +16,7 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo
1816
*/
1917
public function getHasCompareKey()
2018
{
21-
return $this->getOwnerKey();
19+
return $this->ownerKey;
2220
}
2321

2422
/** @inheritdoc */
@@ -28,7 +26,7 @@ public function addConstraints()
2826
// For belongs to relationships, which are essentially the inverse of has one
2927
// or has many relationships, we need to actually query on the primary key
3028
// of the related models matching on the foreign key that's on a parent.
31-
$this->query->where($this->getOwnerKey(), '=', $this->parent->{$this->foreignKey});
29+
$this->query->where($this->ownerKey, '=', $this->parent->{$this->foreignKey});
3230
}
3331
}
3432

@@ -38,9 +36,7 @@ public function addEagerConstraints(array $models)
3836
// We'll grab the primary key name of the related models since it could be set to
3937
// a non-standard name and not "id". We will then construct the constraint for
4038
// our eagerly loading query so it returns the proper models from execution.
41-
$key = $this->getOwnerKey();
42-
43-
$this->query->whereIn($key, $this->getEagerModelKeys($models));
39+
$this->query->whereIn($this->ownerKey, $this->getEagerModelKeys($models));
4440
}
4541

4642
/** @inheritdoc */
@@ -49,16 +45,6 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery,
4945
return $query;
5046
}
5147

52-
/**
53-
* Get the owner key with backwards compatible support.
54-
*
55-
* @return string
56-
*/
57-
public function getOwnerKey()
58-
{
59-
return property_exists($this, 'ownerKey') ? $this->ownerKey : $this->otherKey;
60-
}
61-
6248
/**
6349
* Get the name of the "where in" method for eager loading.
6450
*

src/Relations/BelongsToMany.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
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
{
@@ -123,7 +122,7 @@ public function sync($ids, $detaching = true)
123122
// First we need to attach any of the associated models that are not currently
124123
// in this joining table. We'll spin through the given IDs, checking to see
125124
// if they exist in the array of current ones, and if not we will insert.
126-
$current = $this->parent->{$this->getRelatedKey()} ?: [];
125+
$current = $this->parent->{$this->relatedPivotKey} ?: [];
127126

128127
// See issue #256.
129128
if ($current instanceof Collection) {
@@ -196,7 +195,7 @@ public function attach($id, array $attributes = [], $touch = true)
196195
}
197196

198197
// Attach the new ids to the parent model.
199-
$this->parent->push($this->getRelatedKey(), (array) $id, true);
198+
$this->parent->push($this->relatedPivotKey, (array) $id, true);
200199

201200
if (! $touch) {
202201
return;
@@ -220,7 +219,7 @@ public function detach($ids = [], $touch = true)
220219
$ids = (array) $ids;
221220

222221
// Detach all ids from the parent model.
223-
$this->parent->pull($this->getRelatedKey(), $ids);
222+
$this->parent->pull($this->relatedPivotKey, $ids);
224223

225224
// Prepare the query to select all related objects.
226225
if (count($ids) > 0) {
@@ -316,16 +315,6 @@ protected function formatSyncList(array $records)
316315
return $results;
317316
}
318317

319-
/**
320-
* Get the related key with backwards compatible support.
321-
*
322-
* @return string
323-
*/
324-
public function getRelatedKey()
325-
{
326-
return property_exists($this, 'relatedPivotKey') ? $this->relatedPivotKey : $this->relatedKey;
327-
}
328-
329318
/**
330319
* Get the name of the "where in" method for eager loading.
331320
*

src/Relations/MorphTo.php

Lines changed: 1 addition & 13 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 */
@@ -18,7 +16,7 @@ public function addConstraints()
1816
// For belongs to relationships, which are essentially the inverse of has one
1917
// or has many relationships, we need to actually query on the primary key
2018
// of the related models matching on the foreign key that's on a parent.
21-
$this->query->where($this->getOwnerKey(), '=', $this->parent->{$this->foreignKey});
19+
$this->query->where($this->ownerKey, '=', $this->parent->{$this->foreignKey});
2220
}
2321
}
2422

@@ -34,16 +32,6 @@ protected function getResultsByType($type)
3432
return $query->whereIn($key, $this->gatherKeysByType($type, $instance->getKeyType()))->get();
3533
}
3634

37-
/**
38-
* Get the owner key with backwards compatible support.
39-
*
40-
* @return string
41-
*/
42-
public function getOwnerKey()
43-
{
44-
return property_exists($this, 'ownerKey') ? $this->ownerKey : $this->otherKey;
45-
}
46-
4735
/**
4836
* Get the name of the "where in" method for eager loading.
4937
*

0 commit comments

Comments
 (0)