the deleting user is blocked if they have subscribed to forum
We have used the simple_discussion gem in our rails application but the error is caused when the user is destroyed.
PG::ForeignKeyViolation: ERROR: update or delete on table "users" violates foreign key constraint "fk_rails_bc51c711fd" on table "forum_threads"
DETAIL: Key (id)=(1) is still referenced from table "forum_threads".
I don't know how simple_discussion works, but the error by itself tell us what is going on.
Probably, you have a "belongs_to :user", so you cant delete a user because this relation.
I can see two way to handle it:
First -> when deleting a user, delete all forum_threads related to this user. At Users model, add "has_many :forum_threads, dependent: :destroy".
Second -> when deleting a user, nullify user_id at forum_threads table. At Users model, add "has_many :forum_threads, dependent: :nullify"
https://guides.rubyonrails.org/association_basics.html#options-for-has-many-class-name