This project is archived and is in readonly mode.
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
end
class Tag < ActiveRecord::Base
belongs_to :project, :touch => true
end
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:in
save_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:in
transaction'
...application/vendor/rails/activerecord/lib/active_record/transactions.rb:182:in
transaction'
...application/vendor/rails/activerecord/lib/active_record/transactions.rb:200:in
save!'
...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:in
save!'
...application/vendor/rails/activerecord/lib/active_record/timestamp.rb:37:in
touch'
...application/vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:221:in
send'
...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:in
belongs_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:in
evaluate_method'
...application/vendor/rails/activesupport/lib/active_support/callbacks.rb:166:in
call'
...application/vendor/rails/activesupport/lib/active_support/callbacks.rb:93:in
run'
...application/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in
each'
...application/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in
send'
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 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).
-
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.
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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>