如何修复多重分配问题?在Rails上4

时间:2014-10-27 17:50:27

标签: sql ruby-on-rails postgresql ruby-on-rails-4

所以,我有3个表,帐户,用户和订阅,所有这些表都有deleted_at列。现在,当我删除帐户时,请求会立即发送到所有模型,从而导致多次分配错误,如下所示:

Started DELETE "/admin/accounts/3" for 127.0.0.1 at 2014-10-27 19:38:48 +0200
Processing by SaasAdmin::AccountsController#destroy as HTML
  Parameters: {"authenticity_token"=>"qo8NxYhezJUz2YylGxHlx2ou125UNoRuEcXbrnzyiN4=", "id"=>"3"}
  AppSetting Load (0.3ms)  SELECT "app_settings".* FROM "app_settings" ORDER BY "app_settings"."id" ASC LIMIT 1
  Tag Load (0.2ms)  SELECT "tags".* FROM "tags" WHERE "tags"."id" = $1 LIMIT 1  [["id", 22]]
  SaasAdmin Load (0.2ms)  SELECT "saas_admins".* FROM "saas_admins" WHERE "saas_admins"."id" = 4 ORDER BY "saas_admins"."id" ASC LIMIT 1
  Account Load (0.1ms)  SELECT "accounts".* FROM "accounts" WHERE (accounts.deleted_at IS NULL) AND "accounts"."id" = $1 LIMIT 1  [["id", "3"]]
   (0.1ms)  BEGIN
  Subscription Load (0.3ms)  SELECT "subscriptions".* FROM "subscriptions" WHERE (subscriptions.deleted_at IS NULL) AND "subscriptions"."subscriber_id" = $1 AND "subscriptions"."subscriber_type" = $2 LIMIT 1  [["subscriber_id", 3], ["subscriber_type", "Account"]]
  SQL (0.3ms)  UPDATE "subscriptions" SET deleted_at = '2014-10-27 17:38:48.909001', deleted_at = '2014-10-27 17:38:48.909025' WHERE (subscriptions.deleted_at IS NULL) AND "subscriptions"."id" = 3
PG::SyntaxError: ERROR:  multiple assignments to same column "deleted_at"
: UPDATE "subscriptions" SET deleted_at = '2014-10-27 17:38:48.909001', deleted_at = '2014-10-27 17:38:48.909025' WHERE (subscriptions.deleted_at IS NULL) AND "subscriptions"."id" = 3
   (0.1ms)  ROLLBACK
Completed 500 Internal Server Error in 7ms

 ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR:  multiple assignments to same column "deleted_at"
: UPDATE "subscriptions" SET deleted_at = '2014-10-27 17:38:48.909001', deleted_at = '2014-10-27 17:38:48.909025' WHERE (subscriptions.deleted_at IS NULL) AND "subscriptions"."id" = 3):
  activerecord (4.0.4) lib/active_record/connection_adapters/postgresql_adapter.rb:791:in `async_exec'

此外,sql是作为偏执宝石生成的,因此我们不会编写查找程序。我们做account.destroy,其余的由dependecies。如果有帮助的话,这里是宝石的链接:https://github.com/ActsAsParanoid/acts_as_paranoid

我们可以做些什么来解决这个问题?

请访问Gist链接查看下面的完整日志:https://gist.github.com/rmagnum2002/2358536587bb34dbbc52

0 个答案:

没有答案