内核更新

This commit is contained in:
2017-02-14 09:41:34 +08:00
parent 689376a5d9
commit b355535009
43 changed files with 330 additions and 100 deletions

View File

@@ -18,7 +18,7 @@ use think\Model;
class HasOne extends OneToOne
{
/**
* 构函数
* 构函数
* @access public
* @param Model $parent 上级模型对象
* @param string $model 模型名
@@ -47,12 +47,28 @@ class HasOne extends OneToOne
// 执行关联定义方法
$localKey = $this->localKey;
if ($closure) {
call_user_func_array($closure, [& $this->query]);
call_user_func_array($closure, [ & $this->query]);
}
// 判断关联类型执行查询
return $this->query->where($this->foreignKey, $this->parent->$localKey)->relation($subRelation)->find();
}
/**
* 根据关联条件查询当前模型
* @access public
* @return Query
*/
public function has()
{
$table = $this->query->getTable();
$localKey = $this->localKey;
$foreignKey = $this->foreignKey;
return $this->parent->db()->alias('a')
->whereExists(function ($query) use ($table, $localKey, $foreignKey) {
$query->table([$table => 'b'])->field('b.' . $foreignKey)->whereExp('a.' . $localKey, '=b.' . $foreignKey);
});
}
/**
* 根据关联条件查询当前模型
* @access public