This project is archived and is in readonly mode.

#3461 new
Helmut Juskewycz

Touch called on parent destroy

Reported by Helmut Juskewycz | November 5th, 2009 @ 09:46 AM

I have two models: Project and Tags

class Project < ActiveRecord::Base
  has_many :tags, :dependent => :destroy

class Tag < ActiveRecord::Base
  belongs_to :project, :touch => true

And every project must have at least one tag (I skipped the valiations). So when project.destroy is called, I get the following error message:

...application/vendor/rails/activerecord/lib/active_record/validations.rb:1090:in save_without_dirty!' ...application/vendor/rails/activerecord/lib/active_record/dirty.rb:87:insave_without_transactions!' ...application/vendor/rails/activerecord/lib/active_record/transactions.rb:200:in save!' ...application/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:136:intransaction' ...application/vendor/rails/activerecord/lib/active_record/transactions.rb:182:in transaction' ...application/vendor/rails/activerecord/lib/active_record/transactions.rb:200:insave!' ...application/vendor/rails/activerecord/lib/active_record/transactions.rb:208:in rollback_active_record_state!' ...application/vendor/rails/activerecord/lib/active_record/transactions.rb:200:insave!' ...application/vendor/rails/activerecord/lib/active_record/timestamp.rb:37:in touch' ...application/vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:221:insend' ...application/vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:221:in method_missing' ...application/vendor/rails/activerecord/lib/active_record/associations.rb:1380:inbelongs_to_touch_after_save_or_destroy_for_project' ...application/vendor/rails/activesupport/lib/active_support/callbacks.rb:178:in send' ...application/vendor/rails/activesupport/lib/active_support/callbacks.rb:178:inevaluate_method' ...application/vendor/rails/activesupport/lib/active_support/callbacks.rb:166:in call' ...application/vendor/rails/activesupport/lib/active_support/callbacks.rb:93:inrun' ...application/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in each' ...application/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:insend'

It seems that every tag.destroy call project.touch, and my guess the last touch is invalid because the project needs at least one tag. In my opinion, when the project is destroyed it shouldn't be touched at all.

Does someone know a workaround? Thanks

Comments and changes to this ticket

  • joel

    joel August 3rd, 2010 @ 05:34 PM

    • Importance changed from “” to “”

    Why has this not been addressed? This is affecting my application also, you should be able to limit :touch to save, update, or destroy. Otherwise validations are running on an object that is trying to be destroyed (the parent in the dependent destroy).

  • Neeraj Singh

    Neeraj Singh August 3rd, 2010 @ 06:54 PM

    @Joel what version of rails you are using?

  • perrycz

    perrycz September 15th, 2010 @ 01:03 AM

    • Tag changed from 2.3.4, :dependent, :destroy, active_record, destroy, touch to 2.3.4, 2.3.8, 2.3.9, :dependent, :destroy, active_record, destroy, touch

    Same here. Tested on Rails 2.3.8 and 2.3.9.

  • Tony Daly

    Tony Daly January 24th, 2011 @ 06:25 PM

    Any news on this? Also experiencing this in 2.3.8.

  • Ryan Wallace

    Ryan Wallace March 16th, 2011 @ 10:39 PM

    FYI: This is fixed in Rails 3

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>