[Feature idea] Allow custom dependent callbacks on has_many Associations

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[Feature idea] Allow custom dependent callbacks on has_many Associations

Bálint Erdős
I was thinking of implementing a way to use custom method names for dependent has_many Associations.
This way I wouldn't have to use workarounds like rewriting destroy methods, or stuffing code handling other models into methods for before_destroy callbacks.

class Thing < ApplicationRecord
  belongs_to :owner, class_name: 'User'
  def reset_owner
    # set owner to another user based on settings

class User < ApplicationRecord
  has_many :things, dependent: :reset_owner

I don't think other kinds of Associations would need to support this.

What do you think?

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.