From 05fba9a15273e6d64c4830c67e9ba19b3b9f0809 Mon Sep 17 00:00:00 2001 From: Daniel Sullivan Date: Thu, 19 Sep 2019 17:34:25 +0900 Subject: [PATCH] Add UpdateModel function to allow updating a model without needing to specify parameters manually --- .idea/.gitignore | 2 ++ main.go | 8 ++++++++ 2 files changed, 10 insertions(+) create mode 100644 .idea/.gitignore diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..5c98b428 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/main.go b/main.go index 95ae72f1..a8a13e3f 100644 --- a/main.go +++ b/main.go @@ -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)