1 year ago

#308984

test-img

Gustavo Borges

Multitenancy (Acts as Tenant gem): How to delete a tenant?

I am using the Acts as Tenant gem for Rails and, if I understood it right when using the acts_as_tenant :tenant on models/course.rb, it automatically includes the relationships between models (i.e. belongs_to :tenant and has_many :courses).

So, now I am trying to delete a tenant and I get the error below:

[3e5da695-5075-4901-b013-dd2d1f7afcda] app/controllers/super_admin/tenants_controller.rb:54:in `destroy'
2022-03-18T20:25:53.000000+00:00 app[postgres.3099747]: [DATABASE] [13-1]  sql_error_code = 23503 ERROR:  update or delete on table "tenants" violates foreign key constraint "fk_rails_ff24ac10ab" on table "courses"
2022-03-18T20:25:53.000000+00:00 app[postgres.3099747]: [DATABASE] [13-2]  sql_error_code = 23503 DETAIL:  Key (id)=(1177) is still referenced from table "courses".
2022-03-18T20:25:53.000000+00:00 app[postgres.3099747]: [DATABASE] [13-3]  sql_error_code = 23503 STATEMENT:  DELETE FROM "tenants" WHERE "tenants"."id" = $1

And I get a 500 error. Should I add all the has_many relationships to the Tenant model and include dependent: :destroy? (I want to delete those objects as well)

ruby-on-rails

ruby

postgresql

multi-tenant

acts-as-tenant

0 Answers

Your Answer

Accepted video resources