mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 23:02:48 +08:00
改进关联属性的输出
This commit is contained in:
@@ -658,14 +658,22 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
if (is_string($append)) {
|
if (is_string($append)) {
|
||||||
$append = explode(',', $append);
|
$append = explode(',', $append);
|
||||||
}
|
}
|
||||||
$model = $this->getAttr($relation);
|
|
||||||
|
$relation = Loader::parseName($relation, 1, false);
|
||||||
|
|
||||||
|
if (isset($this->relation[$relation])) {
|
||||||
|
$model = $this->relation[$relation];
|
||||||
|
} else {
|
||||||
|
$model = $this->getAttr($relation);
|
||||||
|
}
|
||||||
|
|
||||||
if ($model instanceof Model) {
|
if ($model instanceof Model) {
|
||||||
foreach ($append as $key => $attr) {
|
foreach ($append as $key => $attr) {
|
||||||
$key = is_numeric($key) ? $attr : $key;
|
$key = is_numeric($key) ? $attr : $key;
|
||||||
if ($this->__isset($key)) {
|
if (isset($this->data[$key])) {
|
||||||
throw new Exception('bind attr has exists:' . $key);
|
throw new Exception('bind attr has exists:' . $key);
|
||||||
} else {
|
} else {
|
||||||
$this->setAttr($key, $model->$attr);
|
$this->data[$key] = $model->$attr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -778,7 +786,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
// 关联模型数据集
|
// 关联模型数据集
|
||||||
$arr = [];
|
$arr = [];
|
||||||
foreach ($val as $k => $value) {
|
foreach ($val as $k => $value) {
|
||||||
$arr[$k] = $this->subToArray($value, $visible, $hidden, $k);
|
$arr[$k] = $this->subToArray($value, $visible, $hidden, $key);
|
||||||
}
|
}
|
||||||
$item[$key] = $arr;
|
$item[$key] = $arr;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user