Home Rails, polymorphic association. Destroy with "touch: true", useless steps
Reply: 0

Rails, polymorphic association. Destroy with "touch: true", useless steps

user891
1#
user891 Published in May 21, 2018, 10:49 pm

I'm on Rails 5.

I have a polymorphic association like this:

models/enjoy_level.rb:

class EnjoyLevel < ApplicationRecord
  belongs_to :enjoyable, polymorphic: true, touch: true, optional: true
end

models/mother.rb:

class Mother < ApplicationRecord
  has_one :enjoy_level, as: :enjoyable, dependent: :destroy

  accepts_nested_attributes_for :enjoy_level
end

If I destroy one mother (which have touch: true option) it still:

  • destroy the enjoy_level one before;
  • set Mother update_at to now();
  • and finally destroy this Mother record one.

The first and second steps are useless, right?

Where am I wrong?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316533 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO