Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit fef3820

Browse files
Fix getKey check when ($model['id'] === 0)
I have inherited a project which has a row with an id of 0 which causes an exception to be thrown incorrectly. Looking through $model->getKey() I noticed that it returns 'NULL' if a key doesn't exist but will return '(int) 0' if an 'id' key does exist with value of '(int) 0'. '(int) 0' will evaluate as false even though it is in fact the correct value.
1 parent 6214ac2 commit fef3820

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Payloads/DocumentPayload.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class DocumentPayload extends TypePayload
1313
*/
1414
public function __construct(Model $model)
1515
{
16-
if (!$model->getKey()) {
16+
if ($model->getKey() === null) {
1717
throw new Exception(sprintf(
1818
'The key value must be set to construct a payload for the %s instance.',
1919
get_class($model)
@@ -25,4 +25,4 @@ public function __construct(Model $model)
2525
$this->payload['id'] = $model->getKey();
2626
$this->protectedKeys[] = 'id';
2727
}
28-
}
28+
}

0 commit comments

Comments
 (0)