InsertOrUpdate 新增或更新版本标识
()
| 41 | |
| 42 | // InsertOrUpdate 新增或更新版本标识 |
| 43 | func (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 | |
| 58 | func (m *Version) FindByTitle(title string) (version Version) { |
| 59 | orm.NewOrm().QueryTable(m).Filter("title", title).One(&version) |
no test coverage detected