Model类添加getRelation方法用于获取关联属性

This commit is contained in:
thinkphp
2017-04-27 12:39:38 +08:00
parent 9bb01ec145
commit 85b71a3088

View File

@@ -354,6 +354,23 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
return $this;
}
/**
* 获取当前模型的关联模型数据
* @access public
* @param string $name 关联方法名
* @return mixed
*/
public function getRelation($name = null)
{
if (is_null($name)) {
return $this->relation;
} elseif (array_key_exists($name, $this->relation)) {
return $this->relation[$name];
} else {
return;
}
}
/**
* 设置关联数据对象值
* @access public