Skip to content

Commit

Permalink
修正数组查询
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Nov 13, 2024
1 parent 4d1b458 commit 202bbd7
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/db/concern/WhereQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,10 @@ public function where($field, $op = null, $condition = null)
$param = func_get_args();
array_shift($param);

if (is_array($field) && is_array($field[0])) {
$where = function($query) use($field) {
foreach($field as $item) {
$query->where($item[0], $item[1], $item[2]);
}
};
$logic = is_string($op) && 'or' == strtolower($op) ? 'OR' : 'AND';
return $this->parseWhereExp($logic, $where, null, null);
if (is_array($field)) {
return $this->where(function ($query) use ($param, $condition, $op, $field) {
return $query->parseWhereExp('AND', $field, $op, $condition, $param);
});
}
return $this->parseWhereExp('AND', $field, $op, $condition, $param);
}
Expand Down Expand Up @@ -100,14 +96,10 @@ public function whereOr($field, $op = null, $condition = null)
$param = func_get_args();
array_shift($param);

if (is_array($field) && is_array($field[0])) {
$where = function($query) use($field) {
foreach($field as $item) {
$query->whereOr($item[0], $item[1], $item[2]);
}
};
$logic = is_string($op) && 'or' == strtolower($op) ? 'OR' : 'AND';
return $this->parseWhereExp($logic, $where, null, null);
if (is_array($field)) {
return $this->where(function ($query) use ($param, $condition, $op, $field) {
return $query->parseWhereExp('OR', $field, $op, $condition, $param);
});
}

return $this->parseWhereExp('OR', $field, $op, $condition, $param);
Expand Down

1 comment on commit 202bbd7

@axguowen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个改进非常好,终于不用再使用闭包的方式了,不知道能不能同步更新到2.0的分支去,希望能够同步一下,很多项目还是用的2.0

Please sign in to comment.