From a0f49f2d56bc25a5a231afe5dad887ed223e0b1e Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Sun, 29 Aug 2021 13:42:34 +0200 Subject: [PATCH] People: Sync subject name with markers table #22 --- internal/entity/subject.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/entity/subject.go b/internal/entity/subject.go index 69acadc66..d62865621 100644 --- a/internal/entity/subject.go +++ b/internal/entity/subject.go @@ -201,9 +201,16 @@ func (m *Subject) SetName(name string) error { func (m *Subject) UpdateName(name string) error { if err := m.SetName(name); err != nil { return err + } else if err := m.Updates(Values{"SubjectName": m.SubjectName, "SubjectSlug": m.SubjectSlug}); err != nil { + return err + } else if err := Db().Model(&Marker{}). + Where("subject_uid = ? AND subject_src = ?", m.SubjectUID, SrcManual). + Where("marker_name <> '' AND marker_name <> ?", m.SubjectName). + Update(Values{"MarkerName": m.SubjectName}).Error; err != nil { + return err } - return m.Updates(Values{"SubjectName": m.SubjectName, "SubjectSlug": m.SubjectSlug}) + return nil } // Links returns all share links for this entity.