mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
Model类增加appendRelationAttr方法用于追加关联模型的属性到当前模型
This commit is contained in:
@@ -500,6 +500,28 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user