From 9b78974bc9f0dad0242d057b69f543471af2b92d Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Tue, 16 May 2017 12:10:37 +0900 Subject: Fix association with extension issues This fixes the following issues. * `association_scope` doesn't include `default_scope`. Should use `scope` instead. * We can't use `method_missing` for customizing existing method. * We can't use `relation_delegate_class` for sharing extensions. Should extend per association. --- activerecord/lib/active_record/reflection.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activerecord/lib/active_record/reflection.rb') diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 65fdbc2fe4..0bfd59d7bd 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -581,6 +581,10 @@ module ActiveRecord seed + [self] end + def extensions + Array(options[:extend]) + end + protected def actual_source_reflection # FIXME: this is a horrible name -- cgit v1.2.3 From 5734dcd8114cf2958cf4dd40f9402562d7a431fa Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 1 May 2017 05:27:28 +0900 Subject: Don't expose methods and attrs for internal usage --- activerecord/lib/active_record/reflection.rb | 36 +++++++++++++++------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'activerecord/lib/active_record/reflection.rb') diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 429f9a257a..e8ee8279fd 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -287,6 +287,11 @@ module ActiveRecord JoinKeys.new(join_pk(association_klass), join_fk) end + protected + def actual_source_reflection # FIXME: this is a horrible name + self + end + private def join_pk(_) @@ -583,12 +588,6 @@ module ActiveRecord Array(options[:extend]) end - protected - - def actual_source_reflection # FIXME: this is a horrible name - self - end - private def calculate_constructable(macro, options) @@ -761,7 +760,6 @@ module ActiveRecord # Holds all the metadata about a :through association as it was specified # in the Active Record class. class ThroughReflection < AbstractReflection #:nodoc: - attr_reader :delegate_reflection delegate :foreign_key, :foreign_type, :association_foreign_key, :active_record_primary_key, :type, :get_join_keys, to: :source_reflection @@ -987,19 +985,23 @@ module ActiveRecord collect_join_reflections(seed + [self]) end - def collect_join_reflections(seed) - a = source_reflection.add_as_source seed - if options[:source_type] - through_reflection.add_as_polymorphic_through self, a - else - through_reflection.add_as_through a + # TODO Change this to private once we've dropped Ruby 2.2 support. + # Workaround for Ruby 2.2 "private attribute?" warning. + protected + attr_reader :delegate_reflection + + def actual_source_reflection # FIXME: this is a horrible name + source_reflection.actual_source_reflection end - end private - - def actual_source_reflection # FIXME: this is a horrible name - source_reflection.send(:actual_source_reflection) + def collect_join_reflections(seed) + a = source_reflection.add_as_source seed + if options[:source_type] + through_reflection.add_as_polymorphic_through self, a + else + through_reflection.add_as_through a + end end def primary_key(klass) -- cgit v1.2.3