多租户(充当租户 gem):如何删除租户?

发布于 2025-01-15 10:20:51 字数 1097 浏览 3 评论 0 原文

我正在使用 Acts as Tenant gem for Rails 并且,如果我在使用 models/course.rb 上的 >acts_as_tenant :tenant,它自动包含模型之间的关系(即 belongs_to :tenanthas_many :courses)。

因此,现在我尝试删除租户,但出现以下错误:

[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

并且出现 500 错误。我是否应该将所有 has_many 关系添加到租户模型并包含 dependent: :destroy ? (我也想删除这些对象)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文