改进一对一查询

This commit is contained in:
thinkphp
2018-02-07 12:10:28 +08:00
parent 357052f1b4
commit ccfe9ad612
2 changed files with 33 additions and 0 deletions

View File

@@ -220,4 +220,21 @@ class BelongsTo extends OneToOne
return $this->parent->setRelation($this->relation, null);
}
/**
* 执行基础查询(仅执行一次)
* @access protected
* @return void
*/
protected function baseQuery()
{
if (empty($this->baseQuery)) {
if (isset($this->parent->{$this->foreignKey})) {
// 关联查询带入关联条件
$this->query->where($this->localKey, '=', $this->parent->{$this->foreignKey});
}
$this->baseQuery = true;
}
}
}

View File

@@ -190,4 +190,20 @@ class HasOne extends OneToOne
}
}
/**
* 执行基础查询(仅执行一次)
* @access protected
* @return void
*/
protected function baseQuery()
{
if (empty($this->baseQuery)) {
if (isset($this->parent->{$this->localKey})) {
// 关联查询带入关联条件
$this->query->where($this->foreignKey, '=', $this->parent->{$this->localKey});
}
$this->baseQuery = true;
}
}
}