mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-08-30 12:45:32 +08:00
改进Model类的has和hasWhere方法
This commit is contained in:
@@ -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'])->whereExp('a.' . $localKey, '=b.' . $foreignKey);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据关联条件查询当前模型
|
||||
* @access public
|
||||
|
||||
Reference in New Issue
Block a user