mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
Model类增加appendRelationAttr方法用于追加关联模型的属性到当前模型
This commit is contained in:
@@ -500,6 +500,28 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置附加关联对象的属性
|
||||||
|
* @access public
|
||||||
|
* @param string $relation 关联方法
|
||||||
|
* @param string|array $append 追加属性名
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function appendRelationAttr($relation, $append)
|
||||||
|
{
|
||||||
|
if (is_string($append)) {
|
||||||
|
$append = explode(',', $append);
|
||||||
|
}
|
||||||
|
$model = $this->getAttr($relation);
|
||||||
|
if ($model instanceof Model) {
|
||||||
|
foreach ($append as $key => $attr) {
|
||||||
|
$key = is_numeric($key) ? $attr : $key;
|
||||||
|
$this->setAttr($key, $model->$attr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置需要隐藏的输出属性
|
* 设置需要隐藏的输出属性
|
||||||
* @access public
|
* @access public
|
||||||
|
|||||||
Reference in New Issue
Block a user