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

Does it work with Foreign Key database constraints? #4

Open
iamonkara opened this issue Sep 8, 2023 · 1 comment
Open

Does it work with Foreign Key database constraints? #4

iamonkara opened this issue Sep 8, 2023 · 1 comment

Comments

@iamonkara
Copy link

image

I get these errors on a has_one and belongs_to association

/home/onkara/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:768:in `exec_params': ERROR:  update or delete on table "users" violates foreign key constraint "fk_rails_5676777bf1" on table "settings" (PG::ForeignKeyViolation)

@jaynetics
Copy link
Owner

jaynetics commented Sep 9, 2023

hi!

this gem does not take special care of DB constraints.

it basically just piggy-backs on active_records dependent: option and triggers at the same time as e.g. dependent: :destroy.

as a result, it should only run into trouble in the same scenarios where a (full chain of) dependent: :destroy callbacks would also run into trouble, if i'm not mistaken.

its a bit hard to tell what's going wrong without knowing the exact setup of relations and full stacktrace.

edit: actually what i said above is not universally true because delete_recursively deletes stuff in the relation tree depth-first after the first record is deleted, whereas dependent: :destroy proceeds breadth-first, so it might make a difference when it comes to constraints and perhaps this "traversal strategy" should be configurable.

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

2 participants