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

Postgres 12 + Rails 6.1: RETURNING "id" issue #391

Closed
bb opened this issue Dec 1, 2021 · 1 comment
Closed

Postgres 12 + Rails 6.1: RETURNING "id" issue #391

bb opened this issue Dec 1, 2021 · 1 comment

Comments

@bb
Copy link

bb commented Dec 1, 2021

I'm getting errors with Postgres 12.x and Rails 6.1 when doing any modifications on the hierarchy like simply trying to set a parent and saving the model or doing a full rebuild.

/home/app/webapp/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/postgresql_adapter.rb:672:in `exec_params': PG::UndefinedColumn: ERROR:  column "id" does not exist (ActiveRecord::StatementInvalid)
LINE 1: ...ndant_id", "generations") VALUES ($1, $2, $3) RETURNING "id"

The hierarchies table exists and has the 3 expected columns but no id column as generated by the migration, so the RETURNING "id" must not be there, or maybe RETURNING "*" or similar. Digging through AR source code, this uses primary_key or false, so one might be able to set the primary_key to false in the Hierarchy class for the model. However, when setting primary_key to nil later, I got another error: home/app/webapp/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.4.1/lib/active_record/reflection.rb:307:in primary_key': Unknown primary key for table ... `

If it may be relevant for the issue: My data structure in multiple classes (saved as STI) however not all of the many classes have closure_tree. The STI root class does not but one Subclass FooWithHierarchy (and with more subclasses of it) have_closure_tree.

I have another quite similar situation in another project, also Rails 6.1 and identical Gem versions but PG 13 which does not seem to have this issue. However, it started earlier and thus may have been populated before any breaking changes. So.... very confusing why one seems to work and one doesn't.

@bb
Copy link
Author

bb commented Dec 14, 2021

Closing because #392 is a much better explanation of the same issue.

@bb bb closed this as completed Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant