[Feature idea] Allow custom dependent callbacks on has_many Associations
15 views
Skip to first unread message
Bálint Erdős
unread,
Jun 3, 2017, 3:06:52 AM6/3/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails: Core
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
end
end
class User < ApplicationRecord
has_many :things, dependent: :reset_owner
end
I don't think other kinds of Associations would need to support this.