Skip to content

Commit

Permalink
check for real primary key
Browse files Browse the repository at this point in the history
taylorotwell committed Aug 2, 2017

Unverified

This user has not yet uploaded their public signing key.
1 parent cfa39f7 commit 8d82618
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/Pivot.php
Original file line number Diff line number Diff line change
@@ -95,6 +95,10 @@ public static function fromRawAttributes(Model $parent, $attributes, $table, $ex
*/
protected function setKeysForSaveQuery(Builder $query)
{
if (isset($this->attributes[$this->getKeyName()])) {
return parent::setKeysForSaveQuery($query);
}

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

return $query->where($this->relatedKey, $this->getAttribute($this->relatedKey));
@@ -107,6 +111,10 @@ protected function setKeysForSaveQuery(Builder $query)
*/
public function delete()
{
if (isset($this->attributes[$this->getKeyName()])) {
return parent::delete();
}

return $this->getDeleteQuery()->delete();
}

0 comments on commit 8d82618

Please sign in to comment.