Skip to content

Commit 9dd9dc2

Browse files
committed
修正order方法传数组的别名问题
1 parent b0a9ecd commit 9dd9dc2

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/db/BaseQuery.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -797,11 +797,7 @@ public function order(string | array | Raw $field, string $order = '')
797797
}
798798

799799
if (is_string($field)) {
800-
$field = $this->getFieldMap($field) ?: $field;
801-
if (!empty($this->options['via']) && !str_contains($field, '.') && !str_contains($field, '->')) {
802-
$field = $this->options['via'] . '.' . $field;
803-
}
804-
800+
$field = $this->parseOrderField($this->getFieldMap($field) ?: $field);
805801
if (is_string($field) && strpos($field, '->')) {
806802
[$alias, $attr] = explode('->', $field, 2);
807803

@@ -820,9 +816,9 @@ public function order(string | array | Raw $field, string $order = '')
820816
} elseif (!empty($this->options['via'])) {
821817
foreach ($field as $key => $val) {
822818
if (is_numeric($key)) {
823-
$field[$key] = $this->options['via'] . '.' . $val;
819+
$field[$key] = $this->parseOrderField($val);
824820
} else {
825-
$field[$this->options['via'] . '.' . $key] = $val;
821+
$field[$this->parseOrderField($key)] = $val;
826822
unset($field[$key]);
827823
}
828824
}
@@ -841,6 +837,13 @@ public function order(string | array | Raw $field, string $order = '')
841837
return $this;
842838
}
843839

840+
protected function parseOrderField(string $field): string
841+
{
842+
if (!empty($this->options['via']) && !str_contains($field, '.') && !str_contains($field, '->')) {
843+
$field = $this->options['via'] . '.' . $field;
844+
}
845+
return $field;
846+
}
844847
/**
845848
* 分页查询.
846849
*

0 commit comments

Comments
 (0)