gorm global db,条件一直在增加。重复最后一个条件

时间:2018-11-22 06:16:26

标签: gorm

为什么sql条件一直在增加?是数据库缓存还是全局数据库?

UPDATE `topic` SET `modified_at` = '1542857567', `modified_by` = '1', `name` = '主题名称' 
          WHERE `topic`.`deleted_at` IS NULL AND ((id = '1' ))
UPDATE `topic` SET `modified_at` = '1542857697', `modified_by` = '1', `name` = '主题名称'  
          WHERE `topic`.`deleted_at` IS NULL AND ((id = '1' ) AND (id = '1' ))
UPDATE `topic` SET `modified_at` = '1542857699', `modified_by` = '1', `name` = '主题名称'  
          WHERE `topic`.`deleted_at` IS NULL AND ((id = '1' ) AND (id = '1' ) AND (id = '1' ))

mdels.go/SetUp中初始化gorm.DB

已执行查询操作:重复AND ((id = '1' )

func EditTopic(id int, data interface{}) error {
	fmt.Println(db) //map[name:主题名称 modified_by:1]
	db = db.Model(&Topic{}).Where("id = ? ", id).Updates(data)
	err := db.Error
	logging.Info(err)
	if err != nil {
		return err
	}
	return nil
}

0 个答案:

没有答案