内核更新
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user