Add UpdateModel function to allow updating a model without needing to specify parameters manually
This commit is contained in:
parent
cc18a6bb74
commit
05fba9a152
2
.idea/.gitignore
generated
vendored
Normal file
2
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/workspace.xml
|
8
main.go
8
main.go
@ -460,6 +460,14 @@ func (s *DB) UpdateColumns(values interface{}) *DB {
|
|||||||
callCallbacks(s.parent.callbacks.updates).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
|
// Save update value in database, if the value doesn't have primary key, will insert it
|
||||||
func (s *DB) Save(value interface{}) *DB {
|
func (s *DB) Save(value interface{}) *DB {
|
||||||
scope := s.NewScope(value)
|
scope := s.NewScope(value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user