Skip to content

Commit

Permalink
Where clauses should use original attribute values
Browse files Browse the repository at this point in the history
With current implementation, it is impossible to update any of the foreign or related keys in Pivot instance, without executing raw SQL queries, as the generated query is using current attribute values instead of the original values. This commit will fix this issue.
  • Loading branch information
mnishihan authored Feb 5, 2018
1 parent 6a5eb90 commit e9f37ed
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Illuminate/Database/Eloquent/Relations/Pivot.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ protected function setKeysForSaveQuery(Builder $query)
return parent::setKeysForSaveQuery($query);
}

$query->where($this->foreignKey, $this->getAttribute($this->foreignKey));
$query->where($this->foreignKey, $this->getOriginal($this->foreignKey));

return $query->where($this->relatedKey, $this->getAttribute($this->relatedKey));
return $query->where($this->relatedKey, $this->getOriginal($this->relatedKey));
}

/**
Expand All @@ -126,8 +126,8 @@ public function delete()
protected function getDeleteQuery()
{
return $this->newQuery()->where([
$this->foreignKey => $this->getAttribute($this->foreignKey),
$this->relatedKey => $this->getAttribute($this->relatedKey),
$this->foreignKey => $this->getOriginal($this->foreignKey),
$this->relatedKey => $this->getOriginal($this->relatedKey),
]);
}

Expand Down

0 comments on commit e9f37ed

Please sign in to comment.