mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 07:02:47 +08:00
模型的hasWhere方法增加fields参数
This commit is contained in:
@@ -81,14 +81,16 @@ class HasOne extends OneToOne
|
||||
/**
|
||||
* 根据关联条件查询当前模型
|
||||
* @access public
|
||||
* @param mixed $where 查询条件(数组或者闭包)
|
||||
* @param mixed $where 查询条件(数组或者闭包)
|
||||
* @param mixed $fields 字段
|
||||
* @return Query
|
||||
*/
|
||||
public function hasWhere($where = [])
|
||||
public function hasWhere($where = [], $fields = null)
|
||||
{
|
||||
$table = $this->query->getTable();
|
||||
$model = basename(str_replace('\\', '/', get_class($this->parent)));
|
||||
$relation = basename(str_replace('\\', '/', $this->model));
|
||||
|
||||
if (is_array($where)) {
|
||||
foreach ($where as $key => $val) {
|
||||
if (false === strpos($key, '.')) {
|
||||
@@ -97,8 +99,10 @@ class HasOne extends OneToOne
|
||||
}
|
||||
}
|
||||
}
|
||||
$fields = $this->getRelationQueryFields($fields, $model);
|
||||
|
||||
return $this->parent->db()->alias($model)
|
||||
->field($model . '.*')
|
||||
->field($fields)
|
||||
->join($table . ' ' . $relation, $model . '.' . $this->localKey . '=' . $relation . '.' . $this->foreignKey, $this->joinType)
|
||||
->where($where);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user