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
ccbdb32e
authored
Feb 08, 2026
by
Seefs
Committed by
GitHub
Feb 08, 2026
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2815 from wans10/main
fix: 修复模型管理"参与官方同步"与"状态"开关无法保存的问题
parents
286d3d80
dbcf1983
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
6 deletions
+18
-6
model/model_meta.go
+18
-6
No files found.
model/model_meta.go
View file @
ccbdb32e
...
...
@@ -47,7 +47,21 @@ func (mi *Model) Insert() error {
now
:=
common
.
GetTimestamp
()
mi
.
CreatedTime
=
now
mi
.
UpdatedTime
=
now
return
DB
.
Create
(
mi
)
.
Error
// 保存原始值(因为 Create 后可能被 GORM 的 default 标签覆盖为 1)
originalStatus
:=
mi
.
Status
originalSyncOfficial
:=
mi
.
SyncOfficial
// 先创建记录(GORM 会对零值字段应用默认值)
if
err
:=
DB
.
Create
(
mi
)
.
Error
;
err
!=
nil
{
return
err
}
// 使用保存的原始值进行更新,确保零值能正确保存
return
DB
.
Model
(
&
Model
{})
.
Where
(
"id = ?"
,
mi
.
Id
)
.
Updates
(
map
[
string
]
interface
{}{
"status"
:
originalStatus
,
"sync_official"
:
originalSyncOfficial
,
})
.
Error
}
func
IsModelNameDuplicated
(
id
int
,
name
string
)
(
bool
,
error
)
{
...
...
@@ -61,11 +75,9 @@ func IsModelNameDuplicated(id int, name string) (bool, error) {
func
(
mi
*
Model
)
Update
()
error
{
mi
.
UpdatedTime
=
common
.
GetTimestamp
()
return
DB
.
Session
(
&
gorm
.
Session
{
AllowGlobalUpdate
:
false
,
FullSaveAssociations
:
false
})
.
Model
(
&
Model
{})
.
Where
(
"id = ?"
,
mi
.
Id
)
.
Omit
(
"created_time"
)
.
Select
(
"*"
)
.
// 使用 Select 强制更新所有字段,包括零值
return
DB
.
Model
(
&
Model
{})
.
Where
(
"id = ?"
,
mi
.
Id
)
.
Select
(
"model_name"
,
"description"
,
"icon"
,
"tags"
,
"vendor_id"
,
"endpoints"
,
"status"
,
"sync_official"
,
"name_rule"
,
"updated_time"
)
.
Updates
(
mi
)
.
Error
}
...
...
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