Skip to content

Commit 866518b

Browse files
committed
视图模型查询排序字段支持映射
1 parent d0d8d59 commit 866518b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/db/BaseQuery.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,14 +793,24 @@ public function order(string | array | Raw $field, string $order = '')
793793
return $this;
794794
} elseif ($field instanceof Raw) {
795795
$this->options['order'][] = $field;
796-
797796
return $this;
798797
}
799798

800799
if (is_string($field)) {
801-
if (!empty($this->options['via'])) {
800+
$field = $this->getFieldMap($field) ?: $field;
801+
if (!empty($this->options['via']) && !str_contains($field, '.') && !str_contains($field, '->')) {
802802
$field = $this->options['via'] . '.' . $field;
803803
}
804+
805+
if (is_string($field) && strpos($field, '->')) {
806+
[$alias, $attr] = explode('->', $field, 2);
807+
808+
$type = $this->getFieldType($alias);
809+
if (is_null($type)) {
810+
$field = $alias . '.' . $attr;
811+
}
812+
}
813+
804814
if (str_contains($field, ',')) {
805815
$field = array_map('trim', explode(',', $field));
806816
} else {

0 commit comments

Comments
 (0)