From 939fe523126198d43ecedeacc05dd7fdb1eae3d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 17 Sep 2020 22:45:29 +0000 Subject: [PATCH] Stop generating unnecessary methods for association callbacks The instance and predicate methods are used by Rails so there is no need to generate them. --- .../associations/builder/collection_association.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/associations/builder/collection_association.rb b/activerecord/lib/active_record/associations/builder/collection_association.rb index 3a0dee09a2..0c0613d95f 100644 --- a/activerecord/lib/active_record/associations/builder/collection_association.rb +++ b/activerecord/lib/active_record/associations/builder/collection_association.rb @@ -30,8 +30,10 @@ def self.define_extensions(model, name, &block) def self.define_callback(model, callback_name, name, options) full_callback_name = "#{callback_name}_for_#{name}" - # TODO : why do i need method_defined? I think its because of the inheritance chain - model.class_attribute full_callback_name unless model.method_defined?(full_callback_name) + unless model.method_defined?(full_callback_name) + model.class_attribute(full_callback_name, instance_accessor: false, instance_predicate: false) + end + callbacks = Array(options[callback_name.to_sym]).map do |callback| case callback when Symbol -- GitLab