On Friday, June 16, 2017 at 3:49:47 PM UTC-7, Andrei (L.A.) wrote:
>
> 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?
>
Expected, you are calling Dataset#update, not Model#update. Dataset#update
doesn't run model hooks, as it doesn't operate on model instances. If you
must, you can do:
PP.where(id:2).all{|pp| pp.update(name: "2a")}
But that's not very efficient. In general, you are better off using
database triggers for correct timestamp handling. See
sequel_postgresql_triggers if you are using PostgreSQL.
Thanks,
Jeremy
--
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.