Search code examples
ruby-on-rails-3herokucrashdependent-destroy

App crashing on heroku with :dependent => :destroy_all


Note everything works in local enviromnment

This is the code

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

This is with the public_activity gem

the error is

/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) 

if it expects :destroy_all and I wrote :destroy_all and it works locally.. then what is going on here?


Solution

  • To the 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
    

    So in that error message, the part that says (:destroy_all) is just telling you what you provided; the list of what it was expecting is before that. You probably want :destroy instead. Can't say why it worked locally and not on Heroku; might be some sort of gem version problem.