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

兼容field函数,方便实现自定义排序规则 #696

Merged
merged 2 commits into from
Aug 2, 2023

Conversation

wangle201210
Copy link
Contributor

  • Do only one thing
  • Non breaking API changes
  • [] Tested

What did this pull request do?

实现mysql中的 field() 函数,方便自定义 排序的实现

User Case Description

# gen
***.Select(t1.ALL,  t1.BindStatus.Filed(5, 2, 4, 3, 1).As("status")).Order(field.NewField(t1.TableName(), "status"))
# sql
SELECT `t1`.*,FIELD(`t1`.`bind_status`, 5,2,4,3,1) AS `status` FROM `t1` ORDER BY `status`

通过filed字段实现自定义排序,同理其他需要field函数的也可以使用这个方法
所以不单独实现 ORDER BY FIELD(`t1`.`bind_status`, 5,2,4,3,1)

@wangle201210 wangle201210 mentioned this pull request Oct 28, 2022
@jinzhu jinzhu self-requested a review May 10, 2023 09:53
@jinzhu jinzhu merged commit c4d0b25 into go-gorm:master Aug 2, 2023
7 checks passed
jeepc pushed a commit to jeepc/gen that referenced this pull request Nov 20, 2023
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

Successfully merging this pull request may close these issues.

2 participants