Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

orderBy中$isJsonColumn的BUG,orderBy('a.id','desc') 现在直接报错 #2134

Open
putianxin opened this issue Sep 3, 2024 · 0 comments
Open

Comments

@putianxin
Copy link

putianxin commented Sep 3, 2024

  • Laravel Version: 9
  • PHP Version: 8.0
  • Dcat Admin Version: 2.2.3

Description:

orderBy('a.id','desc')是laravel排序的基本写法。
现在在文件src/Repositories/EloquentRepository.php第222行写到:
$this->setOrderBy(
$model,
str_replace('.', '->', $column),
$type,
$cast);
将$column 原本的a.id 转换成了 a->id

在setOrderBy方法中:
$isJsonColumn = Str::contains($column, '->');

if ($isJsonColumn) {
$explodedCols = explode('->', $column);
// json字段排序
$col = $this->wrapMySqlColumn(array_shift($explodedCols));
$parts = implode('.', $explodedCols);
$column = "JSON_UNQUOTE(JSON_EXTRACT({$col}, '$.{$parts}'))";
}
这个$isJsonColumn就必然为true了
结果就是正常的ORDER BY A.id 变成了ORDER BY JSON_UNQUOTE(JSON_EXTRACT(a, '$.id')"
成功报错。
PS:想骂人但是忍了

Steps To Reproduce:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant