Skip to content

Commit

Permalink
[6.x] Port whereKey fix and bugfix for null type (#34031)
Browse files Browse the repository at this point in the history
* [7.x] Cast primary key to string when $keyType is string (#33930)

* Cast primary key to string when $keyType is string

* fix test

* fix remaining tests

* Fix bug with whereKey null

Co-authored-by: Steve Thomas <[email protected]>
  • Loading branch information
driesvints and stevethomas authored Aug 27, 2020
1 parent 0c54827 commit f2b9d7c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ public function whereKey($id)
return $this;
}

if ($id !== null && $this->model->getKeyType() === 'string') {
$id = (string) $id;
}

return $this->where($this->model->getQualifiedKeyName(), '=', $id);
}

Expand All @@ -210,6 +214,10 @@ public function whereKeyNot($id)
return $this;
}

if ($id !== null && $this->model->getKeyType() === 'string') {
$id = (string) $id;
}

return $this->where($this->model->getQualifiedKeyName(), '!=', $id);
}

Expand Down

0 comments on commit f2b9d7c

Please sign in to comment.