改进Model类是__unset和__isset方法判断

This commit is contained in:
thinkphp
2017-04-24 16:11:32 +08:00
parent 2d225b0f80
commit 2b0bfa8e8b

View File

@@ -1975,7 +1975,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
public function __isset($name) public function __isset($name)
{ {
try { try {
if (array_key_exists($name, $this->data)) { if (array_key_exists($name, $this->data) || array_key_exists($name, $this->relation)) {
return true; return true;
} else { } else {
$this->getAttr($name); $this->getAttr($name);
@@ -1995,7 +1995,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
*/ */
public function __unset($name) public function __unset($name)
{ {
unset($this->data[$name]); unset($this->data[$name], $this->relation[$name]);
} }
public function __toString() public function __toString()