Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update on single-attribute models is not supported #185

Open
tagliala opened this issue Oct 25, 2022 · 0 comments
Open

Update on single-attribute models is not supported #185

tagliala opened this issue Oct 25, 2022 · 0 comments

Comments

@tagliala
Copy link
Member

tagliala commented Oct 25, 2022

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
@tagliala tagliala added the bug label Oct 25, 2022
@tagliala tagliala changed the title Chronomodel does not support one-attribute models Chronomodel does not support update on one-attribute models Oct 25, 2022
@tagliala tagliala changed the title Chronomodel does not support update on one-attribute models Chronomodel does not support update on single-attribute models Oct 25, 2022
@tagliala tagliala changed the title Chronomodel does not support update on single-attribute models Update on single-attribute models is not supported Oct 25, 2022
@tagliala tagliala added limitation and removed bug labels Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant