作者 tangxvhui

替换 Updates 方法为Save;Save 必定更新所有字段

... ... @@ -30,7 +30,7 @@ type Article struct {
CountRead int // 浏览数量
CountComment int // 评论数量
Tags []int64 `gorm:"type:jsonb;serializer:json"` //定性标签
Show int // 评论的展示状态(0显示、1不显示)
Show int // 评论的展示状态(1显示、2不显示)
Summary string // 内容概要
MatchUrl map[string]string `gorm:"type:jsonb;serializer:json"` // 匹配文章内容中的url文本
}
... ...
... ... @@ -44,7 +44,7 @@ func (repository *ArticleAndTagRepository) Update(ctx context.Context, conn tran
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -42,7 +42,7 @@ func (repository *ArticleBackupRepository) Update(ctx context.Context, conn tran
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -46,7 +46,7 @@ func (repository *ArticleCommentRepository) Update(ctx context.Context, conn tra
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -42,7 +42,7 @@ func (repository *ArticleDraftRepository) Update(ctx context.Context, conn trans
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -66,7 +66,7 @@ func (repository *ArticleTagRepository) Update(ctx context.Context, conn transac
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -3,6 +3,7 @@ package repository
import (
"context"
"fmt"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
... ... @@ -43,7 +44,7 @@ func (repository *CompanyRepository) Update(ctx context.Context, conn transactio
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
... ... @@ -42,7 +43,7 @@ func (repository *DepartmentRepository) Update(ctx context.Context, conn transac
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
... ... @@ -42,7 +43,7 @@ func (repository *DiscussionAcceptRepository) Update(ctx context.Context, conn t
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
... ... @@ -42,7 +43,7 @@ func (repository *DiscussionOpinionRepository) Update(ctx context.Context, conn
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
... ... @@ -42,7 +43,7 @@ func (repository *DiscussionRepository) Update(ctx context.Context, conn transac
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -43,7 +43,7 @@ func (repository *MessageBusinessRepository) Update(ctx context.Context, conn tr
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -43,7 +43,7 @@ func (repository *MessageSystemRepository) Update(ctx context.Context, conn tran
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
... ... @@ -42,7 +43,7 @@ func (repository *RoleRepository) Update(ctx context.Context, conn transaction.C
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
... ... @@ -42,7 +43,7 @@ func (repository *UserFollowRepository) Update(ctx context.Context, conn transac
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -42,7 +42,7 @@ func (repository *UserLoveFlagRepository) Update(ctx context.Context, conn trans
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -43,7 +43,7 @@ func (repository *UserReadArticleRepository) Update(ctx context.Context, conn tr
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -3,6 +3,7 @@ package repository
import (
"context"
"fmt"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
... ... @@ -43,7 +44,7 @@ func (repository *UserRepository) Update(ctx context.Context, conn transaction.C
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
... ... @@ -42,7 +43,7 @@ func (repository *UserRoleRepository) Update(ctx context.Context, conn transacti
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
tx = tx.Model(m).Save(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
... ...