From 8d826189bb2db1c177d8605eb9218daa973acb6a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 2 Aug 2017 16:01:25 -0500 Subject: [PATCH] check for real primary key --- src/Illuminate/Database/Eloquent/Relations/Pivot.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Relations/Pivot.php b/src/Illuminate/Database/Eloquent/Relations/Pivot.php index 3179bdc0f958..e80aa911d567 100755 --- a/src/Illuminate/Database/Eloquent/Relations/Pivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Pivot.php @@ -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(); }