Skip to content

Remove compatibility layers with old Laravel versions #2615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions src/Eloquent/HybridRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use function debug_backtrace;
use function is_subclass_of;
use function method_exists;

use const DEBUG_BACKTRACE_IGNORE_ARGS;

Expand Down Expand Up @@ -324,20 +323,6 @@ public function belongsToMany(
);
}

/**
* Get the relationship name of the belongs to many.
*
* @return string
*/
protected function guessBelongsToManyRelation()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was introduced as a compatibility layer in 3e26e05b

{
if (method_exists($this, 'getBelongsToManyCaller')) {
return $this->getBelongsToManyCaller();
}

return parent::guessBelongsToManyRelation();
}

/** @inheritdoc */
public function newEloquentBuilder($query)
{
Expand Down
20 changes: 3 additions & 17 deletions src/Relations/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

use function property_exists;

class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo
{
/**
Expand All @@ -18,7 +16,7 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function getHasCompareKey()
{
return $this->getOwnerKey();
return $this->ownerKey;
}

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

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

$this->query->whereIn($key, $this->getEagerModelKeys($models));
$this->query->whereIn($this->ownerKey, $this->getEagerModelKeys($models));
}

/** @inheritdoc */
Expand All @@ -49,16 +45,6 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery,
return $query;
}

/**
* Get the owner key with backwards compatible support.
*
* @return string
*/
public function getOwnerKey()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was introduced as a compatibility layer in #1116

{
return property_exists($this, 'ownerKey') ? $this->ownerKey : $this->otherKey;
}

/**
* Get the name of the "where in" method for eager loading.
*
Expand Down
17 changes: 3 additions & 14 deletions src/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use function count;
use function is_array;
use function is_numeric;
use function property_exists;

class BelongsToMany extends EloquentBelongsToMany
{
Expand Down Expand Up @@ -123,7 +122,7 @@ public function sync($ids, $detaching = true)
// First we need to attach any of the associated models that are not currently
// in this joining table. We'll spin through the given IDs, checking to see
// if they exist in the array of current ones, and if not we will insert.
$current = $this->parent->{$this->getRelatedKey()} ?: [];
$current = $this->parent->{$this->relatedPivotKey} ?: [];

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

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

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

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

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

/**
* Get the related key with backwards compatible support.
*
* @return string
*/
public function getRelatedKey()
{
return property_exists($this, 'relatedPivotKey') ? $this->relatedPivotKey : $this->relatedKey;
}

/**
* Get the name of the "where in" method for eager loading.
*
Expand Down
14 changes: 1 addition & 13 deletions src/Relations/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo as EloquentMorphTo;

use function property_exists;

class MorphTo extends EloquentMorphTo
{
/** @inheritdoc */
Expand All @@ -18,7 +16,7 @@ public function addConstraints()
// For belongs to relationships, which are essentially the inverse of has one
// or has many relationships, we need to actually query on the primary key
// of the related models matching on the foreign key that's on a parent.
$this->query->where($this->getOwnerKey(), '=', $this->parent->{$this->foreignKey});
$this->query->where($this->ownerKey, '=', $this->parent->{$this->foreignKey});
}
}

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

/**
* Get the owner key with backwards compatible support.
*
* @return string
*/
public function getOwnerKey()
{
return property_exists($this, 'ownerKey') ? $this->ownerKey : $this->otherKey;
}

/**
* Get the name of the "where in" method for eager loading.
*
Expand Down