Skip to content

Commit

Permalink
改进where数组查询
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Dec 18, 2024
1 parent a96c127 commit 4556263
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/db/concern/WhereQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function where($field, $op = null, $condition = null)
$param = func_get_args();
array_shift($param);

if (is_array($field)) {
if (is_array($field) && !empty($field) && array_is_list($field)) {
return $this->where(function ($query) use ($param, $condition, $op, $field) {
return $query->parseWhereExp('AND', $field, $op, $condition, $param);
});
Expand Down Expand Up @@ -98,7 +98,7 @@ public function whereOr($field, $op = null, $condition = null)
$param = func_get_args();
array_shift($param);

if (is_array($field) && !empty($field)) {
if (is_array($field) && !empty($field) && array_is_list($field)) {
return $this->where(function ($query) use ($param, $condition, $op, $field) {
return $query->parseWhereExp('OR', $field, $op, $condition, $param);
});
Expand All @@ -121,7 +121,7 @@ public function whereXor($field, $op = null, $condition = null)
$param = func_get_args();
array_shift($param);

if (is_array($field) && !empty($field)) {
if (is_array($field) && !empty($field) && array_is_list($field)) {
return $this->where(function ($query) use ($param, $condition, $op, $field) {
return $query->parseWhereExp('XOR', $field, $op, $condition, $param);
});
Expand Down

2 comments on commit 4556263

@Ibazhe
Copy link
Contributor

@Ibazhe Ibazhe commented on 4556263 Dec 22, 2024

Choose a reason for hiding this comment

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

这样更新之后的变化就是where条件变成括号里的了,但是如果在where之前有alias的话,这个括号里面的表名不会自动更改

@liu21st
Copy link
Member Author

Choose a reason for hiding this comment

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

数组条件查询本身就不推荐 更多的使用建议是闭包查询

Please sign in to comment.