改进Model类的relation方法

This commit is contained in:
thinkphp
2016-06-22 23:51:20 +08:00
parent 275d93cc38
commit 34579bfa44

View File

@@ -164,10 +164,17 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
/** /**
* 获取关联模型实例 * 获取关联模型实例
* @access protected * @access protected
* @return Relation * @param string|array $relation 关联查询
* @return Relation|Query
*/ */
protected function relation() protected function relation($relation = null)
{ {
if (!is_null($relation)) {
// 执行关联查询
return $this->db->relation($relation);
}
// 获取关联对象实例
if (is_null($this->relation)) { if (is_null($this->relation)) {
$this->relation = new Relation($this); $this->relation = new Relation($this);
} }