Skip to content

Commit

Permalink
Fix relation name for attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
bennothommo committed Feb 22, 2024
1 parent 583051b commit 173c752
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/Database/Concerns/HasRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ protected function handleRelation($relationName)
case 'attachMany':
$relation = $this->validateRelationArgs($relationName, ['public', 'key']);
/** @var AttachOne|AttachMany */
$relationObj = $this->$relationType($relation[0], $relation['public'], $relation['key'], $relationName);
$relationObj = $this->$relationType($relation[0], $relation['public'], $relation['key']);

if ($relation['delete'] ?? false) {
$relationObj->dependent();
Expand Down Expand Up @@ -819,12 +819,8 @@ protected function newMorphToMany(
* This code is a duplicate of Eloquent but uses a Storm relation class.
* @return \Winter\Storm\Database\Relations\AttachOne
*/
public function attachOne($related, $isPublic = true, $localKey = null, $relationName = null)
public function attachOne($related, $isPublic = true, $localKey = null)
{
if (is_null($relationName)) {
$relationName = $this->getRelationCaller();
}

$instance = $this->newRelatedInstance($related);

list($type, $id) = $this->getMorphs('attachment', null, null);
Expand All @@ -834,7 +830,11 @@ public function attachOne($related, $isPublic = true, $localKey = null, $relatio
$localKey = $localKey ?: $this->getKeyName();

$relation = new AttachOne($instance->newQuery(), $this, $table . '.' . $type, $table . '.' . $id, $isPublic, $localKey);
$relation->setRelationName($this->getRelationCaller());
$caller = $this->getRelationCaller();
if (!is_null($caller)) {
$relation->setRelationName($caller);
}

return $relation;
}

Expand All @@ -843,12 +843,8 @@ public function attachOne($related, $isPublic = true, $localKey = null, $relatio
* This code is a duplicate of Eloquent but uses a Storm relation class.
* @return \Winter\Storm\Database\Relations\AttachMany
*/
public function attachMany($related, $isPublic = null, $localKey = null, $relationName = null)
public function attachMany($related, $isPublic = null, $localKey = null)
{
if (is_null($relationName)) {
$relationName = $this->getRelationCaller();
}

$instance = $this->newRelatedInstance($related);

list($type, $id) = $this->getMorphs('attachment', null, null);
Expand All @@ -858,7 +854,11 @@ public function attachMany($related, $isPublic = null, $localKey = null, $relati
$localKey = $localKey ?: $this->getKeyName();

$relation = new AttachMany($instance->newQuery(), $this, $table . '.' . $type, $table . '.' . $id, $isPublic, $localKey);
$relation->setRelationName($this->getRelationCaller());
$caller = $this->getRelationCaller();
if (!is_null($caller)) {
$relation->setRelationName($caller);
}

return $relation;
}

Expand Down

0 comments on commit 173c752

Please sign in to comment.