Why this is not working by default with Sequel::Model.plugin(:timestamps, update_on_create: true)?
środa, 6 stycznia 2021 o 19:27:32 UTC+1 Jeremy Evans napisał(a): > On Wed, Jan 6, 2021 at 10:12 AM Mateusz Urbanski < > [email protected]> wrote: > >> I have a problem with timestamps columns in join table: >> >> [23] pry(main)> *Teacher*.last.add_category(*Category*.last) >> >> I, [2021-01-06T19:07:55.807209 #13867] INFO -- : (0.000301s) SELECT * >> FROM "teachers" ORDER BY "id" DESC LIMIT 1 >> >> I, [2021-01-06T19:07:55.807773 #13867] INFO -- : (0.000180s) SELECT * >> FROM "categories" ORDER BY "id" DESC LIMIT 1 >> >> E, [2021-01-06T19:07:55.808669 #13867] ERROR -- : PG::NotNullViolation: >> ERROR: null value in column "created_at" of relation "categories_teachers" >> violates not-null constraint >> >> DETAIL: Failing row contains (ffe8d90f-4961-4295-b36f-239be713f101, >> ff0747d6-9073-4b67-a0f1-e489f3b16431, null, null).: INSERT INTO >> "categories_teachers" ("teacher_id", "category_id") VALUES >> ('ffe8d90f-4961-4295-b36f-239be713f101', >> 'ff0747d6-9073-4b67-a0f1-e489f3b16431') RETURNING NULL >> >> Sequel::NotNullConstraintViolation: PG::NotNullViolation: ERROR: null >> value in column "created_at" of relation "categories_teachers" violates >> not-null constraint >> >> DETAIL: Failing row contains (ffe8d90f-4961-4295-b36f-239be713f101, >> ff0747d6-9073-4b67-a0f1-e489f3b16431, null, null). >> >> >> from >> /Users/mateuszurbanski/.gem/ruby/3.0.0/gems/sequel-5.40.0/lib/sequel/adapters/postgres.rb:156:in >> >> `exec' >> >> Caused by PG::NotNullViolation: ERROR: null value in column "created_at" >> of relation "categories_teachers" violates not-null constraint >> >> DETAIL: Failing row contains (ffe8d90f-4961-4295-b36f-239be713f101, >> ff0747d6-9073-4b67-a0f1-e489f3b16431, null, null). >> >> >> from >> /Users/mateuszurbanski/.gem/ruby/3.0.0/gems/sequel-5.40.0/lib/sequel/adapters/postgres.rb:156:in >> >> `exec' >> >> >> In this gist there are details of implementation: >> >> https://gist.github.com/MatUrbanski/fe7ad31807b29c86edd546de645b6d09 >> >> How can I fix that? >> > Set a default value of Sequel::CURRENT_TIMESTAMP for the created_at and > updated_at columns. Add a database before update trigger that sets > updated_at to CURRENT_TIMESTAMP. You can see > https://github.com/jeremyevans/sequel_postgresql_triggers for help with > the trigger. > > 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 view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/c80583a7-8312-48fc-a5cd-9362dd4d582bn%40googlegroups.com.
