chronomodel
chronomodel copied to clipboard
Update on single-attribute models is not supported
This rarely presents a problem. However, if you're writing a reduced test case, keep in mind that the minimum supported number of attributes in a table is 2
How to replicate:
# migration
create_table :countries, temporal: true do |t|
t.string :name
end
# model
class Country < ApplicationRecord
include ChronoModel::TimeMachine
validates :name, presence: true
end
> Country.create name: 'Italy'
TRANSACTION (0.1ms) BEGIN
Country Create (5.4ms) INSERT INTO "countries" ("name") VALUES ($1) RETURNING "id" [["name", "Italy"]]
TRANSACTION (0.2ms) COMMIT
> Country.last.update name: 'Italia'
Country Load (0.9ms) SELECT "countries".* FROM "countries" ORDER BY "countries"."id" DESC LIMIT $1 [["LIMIT", 1]]
TRANSACTION (0.1ms) BEGIN
Country Update (4.4ms) UPDATE "countries" SET "name" = $1 WHERE "countries"."id" = $2 [["name", "Italia"], ["id", 1]]
TRANSACTION (0.1ms) ROLLBACK
~/.rvm/gems/ruby-3.1.2/gems/activerecord-7.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:768:in `exec_params': PG::FeatureNotSupported: ERROR: source for a multiple-column UPDATE item must be a sub-SELECT or ROW() expression (ActiveRecord::StatementInvalid)
LINE 1: UPDATE ONLY temporal.countries SET ( "name" ) = ( NEW."name"...
^
QUERY: UPDATE ONLY temporal.countries SET ( "name" ) = ( NEW."name" ) WHERE id = OLD.id
CONTEXT: PL/pgSQL function chronomodel_countries_update() line 34 at SQL statement
~/.rvm/gems/ruby-3.1.2/gems/activerecord-7.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:768:in `exec_params': ERROR: source for a multiple-column UPDATE item must be a sub-SELECT or ROW() expression (PG::FeatureNotSupported)
LINE 1: UPDATE ONLY temporal.countries SET ( "name" ) = ( NEW."name"...
^
QUERY: UPDATE ONLY temporal.countries SET ( "name" ) = ( NEW."name" ) WHERE id = OLD.id
CONTEXT: PL/pgSQL function chronomodel_countries_update() line 34 at SQL statement
Workarounds
- Add timestamps
- Add another field