Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
750dea9d
authored
Aug 10, 2025
by
t0ng7u
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🐛
fix(model): allow zero-value updates so tags/description can be cleared
parent
ac9a1ae8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
4 deletions
+7
-4
model/model_meta.go
+7
-4
No files found.
model/model_meta.go
View file @
750dea9d
...
@@ -73,11 +73,14 @@ func IsModelNameDuplicated(id int, name string) (bool, error) {
...
@@ -73,11 +73,14 @@ func IsModelNameDuplicated(id int, name string) (bool, error) {
// Update 更新现有模型记录
// Update 更新现有模型记录
func
(
mi
*
Model
)
Update
()
error
{
func
(
mi
*
Model
)
Update
()
error
{
// 仅更新需要变更的字段,避免覆盖 CreatedTime
mi
.
UpdatedTime
=
common
.
GetTimestamp
()
mi
.
UpdatedTime
=
common
.
GetTimestamp
()
// 使用 Session 配置并选择所有字段,允许零值(如空字符串)也能被更新
// 排除 created_time,其余字段自动更新,避免新增字段时需要维护列表
return
DB
.
Session
(
&
gorm
.
Session
{
AllowGlobalUpdate
:
false
,
FullSaveAssociations
:
false
})
.
return
DB
.
Model
(
&
Model
{})
.
Where
(
"id = ?"
,
mi
.
Id
)
.
Omit
(
"created_time"
)
.
Updates
(
mi
)
.
Error
Model
(
&
Model
{})
.
Where
(
"id = ?"
,
mi
.
Id
)
.
Omit
(
"created_time"
)
.
Select
(
"*"
)
.
Updates
(
mi
)
.
Error
}
}
// Delete 软删除模型记录
// Delete 软删除模型记录
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment