Method: ModelRecord#update

Defined in:
lib/model/the_record.rb

#update(set: {}, add: nil, to: nil, **args) ⇒ Object

Convient update of the dataset by calling sql-patch

Previously changed attributes are saved to the database.

Using the optional :set argument ad-hoc attributes can be defined

obj = ActiveOrient::Model::Contracts.first
obj.name =  'new_name'
obj.update set: { yesterdays_event: 35 }

updates both, the »name« and the »yesterdays_event«-properties

note: The keyword »set« is optional, thus

obj.update  yesterdays_event: 35

is identical



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/model/the_record.rb', line 137

def update set:{}, add: nil, to: nil, **args
  logger.progname = 'ActiveOrient::Model#Update'

if block_given?			# calling vs. a block is used internally
	# to remove an Item from lists and sets call update(remove: true){ query }
	set_or_remove =  args[:remove].present? ? "remove" : "set"
	transfer_content from: 	 query( "update #{rrid} #{set_or_remove} #{ yield }  return after @this" )&.first
 else
	set.merge! args
#	set.merge updated_at: DateTime.now

	if rid.rid?
		transfer_content from:  db.update( self, set, version )
		# if the updated dataset changed, drop the changes made siently
#		self # return value
	else  # new record
		@attributes.merge! set
		save
	end
end

end