This commit is contained in:
2023-12-22 11:41:24 +08:00
parent bb875bd672
commit 22a04814dc
+7 -6
View File
@@ -49,7 +49,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** @var null|string */ /** @var null|string */
protected ?string $primary = NULL; protected string $primary = '';
/** /**
@@ -187,17 +187,17 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
*/ */
public function hasPrimary(): bool public function hasPrimary(): bool
{ {
return !empty($this->primary); return $this->primary != '';
} }
/** /**
* @return null|string * @return null|string
* @throws * @throws
*/ */
public function getPrimary(): ?string public function getPrimary(): string
{ {
if (!$this->hasPrimary()) { if (!$this->hasPrimary()) {
return NULL; return '';
} }
return $this->primary; return $this->primary;
} }
@@ -222,10 +222,11 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
*/ */
public function getPrimaryValue(): ?int public function getPrimaryValue(): ?int
{ {
if (!$this->hasPrimary()) { if ($this->hasPrimary()) {
return (int)$this->_oldAttributes[$this->getPrimary()] ?? null;
} else {
return null; return null;
} }
return $this->_oldAttributes[$this->getPrimary()] ?? null;
} }
/** /**