【问题标题】:App crashing on heroku with :dependent => :destroy_all应用程序在 heroku 上因 :dependent => :destroy_all 崩溃
【发布时间】:2013-04-14 16:07:55
【问题描述】:

注意一切都在本地环境中正常工作

这是代码

PublicActivity::ORM::ActiveRecord::Activity.class_eval do

attr_accessible :reference_type, :reference_id

has_many :notifications, :dependent => :destroy_all
has_many :users, :through => :notifications



end

这是 public_activity gem

错误是

/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/associations/builder/has_many.rb:20:in `configure_dependency': The :dependent option expects either :destroy, :delete_all, :nullify or :restrict (:destroy_all) (ArgumentError) 

如果它需要 :destroy_all 而我写了 :destroy_all 并且它在本地工作......那么这里发生了什么?

【问题讨论】:

    标签: ruby-on-rails-3 heroku crash dependent-destroy


    【解决方案1】:

    source

    unless options[:dependent].in?([:destroy, :delete_all, :nullify, :restrict])
      raise ArgumentError, "The :dependent option expects either :destroy, :delete_all, " \
                           ":nullify or :restrict (#{options[:dependent].inspect})"
    end
    

    所以在那条错误消息中,(:destroy_all) 的部分只是告诉你你提供了什么;它所期待的清单是在那之前的。你可能想要:destroy。不能说为什么它在本地工作而不是在 Heroku 上工作;可能是某种宝石版本问题。

    【讨论】:

    • would :destroy 按预期工作(删除与删除模型相关的所有通知)?
    • 我认为:destroy 会按预期工作,这里是has_many 的文档:apidock.com/rails/ActiveRecord/Associations/ClassMethods/…。此外,您提供的链接适用于 ActiveRecord Relation 上的 destroy_all 方法。因此,您可以在代码中调用它来销毁所有内容,但不能将其作为模型定义中 has_many 方法的选项提供。
    猜你喜欢
    • 2020-08-12
    • 2015-03-16
    • 2019-05-15
    • 1970-01-01
    • 2013-02-04
    • 2019-02-06
    • 2011-10-03
    相关资源
    最近更新 更多