MCPcopy Create free account
hub / github.com/TruthHun/BookStack / InsertOrUpdate

Method InsertOrUpdate

models/version.go:43–56  ·  view source on GitHub ↗

InsertOrUpdate 新增或更新版本标识

()

Source from the content-addressed store, hash-verified

41
42// InsertOrUpdate 新增或更新版本标识
43func (m *Version) InsertOrUpdate() (err error) {
44 exist := m.FindByTitle(m.Title)
45 o := orm.NewOrm()
46 if exist.Id > 0 { // 版本名称已存在
47 if m.Id == 0 || (m.Id > 0 && exist.Id != m.Id) {
48 err = errors.New("版本名称已存在")
49 return
50 }
51 _, err = o.Update(m)
52 } else {
53 _, err = o.Insert(m)
54 }
55 return
56}
57
58func (m *Version) FindByTitle(title string) (version Version) {
59 orm.NewOrm().QueryTable(m).Filter("title", title).One(&version)

Callers 1

AddVersionsMethod · 0.95

Calls 3

FindByTitleMethod · 0.95
UpdateMethod · 0.45
InsertMethod · 0.45

Tested by

no test coverage detected