Skip to content

Commit

Permalink
check for real primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Aug 2, 2017
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
Expand Up @@ -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));
Expand All @@ -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();
}

Expand Down

0 comments on commit 8d82618

Please sign in to comment.