create table test
(
id int identity
primary key,
name varchar(1000),
imported_at datetime,
import_updated_at datetime
)
class PP < Sequel::Model(:test)
plugin :timestamps, update: :import_updated_at, create: :imported_at
end
# the "create" value gets updated
> p2 = PP.create name: "2"
#<RunImport::PP @values={:id=>2, :name=>"2", :imported_at=>2017-06-16
15:31:03 -0700, :import_updated_at=>nil}>
> p2 = PP.create name: "2"
=> #<RunImport::PP @values={:id=>2, :name=>"2", :imported_at=>2017-06-16
15:31:03 -0700, :import_updated_at=>nil}>
# but the "update" value does not get updated
> p2 = PP.where(id:2).update(name: "2a")
=> 1
> PP.last
=> #<RunImport::PP @values={:id=>2, :name=>"2a", :imported_at=>2017-06-16
15:31:03 -0700, :import_updated_at=>nil}>
Any ideas?
In my situation I am simulating an upsert
record_dataset = where(id: data["id"])
if record_dataset.update(data) > 0 # try updating
puts "--- UPDATED record #{data['id']} ---"
else
create(data) # update failed, will need to insert
puts "--- Created record #{data['id']} ---"
end
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.