Add UpdateModel function to allow updating a model without needing to specify parameters manually

This commit is contained in:
Daniel Sullivan 2019-09-19 17:34:25 +09:00
parent cc18a6bb74
commit 05fba9a152
2 changed files with 10 additions and 0 deletions

2
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,2 @@
# Default ignored files
/workspace.xml

View File

@ -460,6 +460,14 @@ func (s *DB) UpdateColumns(values interface{}) *DB {
callCallbacks(s.parent.callbacks.updates).db
}
func (s *DB) UpdateModel(value interface{}) *DB {
scope := s.NewScope(value).
Set("gorm:update_column", true).
Set("gorm:save_associations", false).
InstanceSet("gorm:update_interface", value)
return scope.callCallbacks(s.parent.callbacks.updates).db
}
// Save update value in database, if the value doesn't have primary key, will insert it
func (s *DB) Save(value interface{}) *DB {
scope := s.NewScope(value)