This commit is contained in:
thinkphp
2017-09-15 18:01:53 +08:00
parent 2a2b3882af
commit 3d181dc52b

View File

@@ -833,17 +833,19 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
if (method_exists($modelRelation, 'getBindAttr')) { if (method_exists($modelRelation, 'getBindAttr')) {
$bindAttr = $modelRelation->getBindAttr(); $bindAttr = $modelRelation->getBindAttr();
foreach ($bindAttr as $key => $attr) { if ($bindAttr) {
$key = is_numeric($key) ? $attr : $key; foreach ($bindAttr as $key => $attr) {
if (isset($this->data[$key])) { $key = is_numeric($key) ? $attr : $key;
throw new Exception('bind attr has exists:' . $key); if (isset($this->data[$key])) {
} else { throw new Exception('bind attr has exists:' . $key);
$item[$key] = $value ? $value->$attr : null; } else {
$item[$key] = $value ? $value->$attr : null;
}
} }
break;
} }
} else {
$item[$name] = $value;
} }
$item[$name] = $value;
} else { } else {
$item[$name] = $this->getAttr($name); $item[$name] = $this->getAttr($name);
} }