Skip to content

Commit 78d6ff6

Browse files
committed
Let through reflections delegate deprecated? to their delegate
I am trying to find the right spot for HABTMs and deprecation. The current logic checking parent_reflection by hand seems suspiciously ad-hoc for me but, at the same time, I was trying to keep the option flag strictly where the user set it. However, through reflections act as their delegate for the most part: delegate_methods = AssociationReflection.public_instance_methods - public_instance_methods delegate(*delegate_methods, to: :delegate_reflection) If I sacrifice the rule above just a bit, the internal has_many of HABTMs could carry the option if present, and the resulting code looks simpler and maybe more aligned with the current design.
1 parent 490411b commit 78d6ff6

File tree

2 files changed

+1
-14
lines changed

2 files changed

+1
-14
lines changed

activerecord/lib/active_record/associations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,7 @@ def destroy_associations
20352035
hm_options[:through] = middle_reflection.name
20362036
hm_options[:source] = join_model.right_reflection.name
20372037

2038-
[:before_add, :after_add, :before_remove, :after_remove, :autosave, :validate, :join_table, :class_name, :extend, :strict_loading].each do |k|
2038+
[:before_add, :after_add, :before_remove, :after_remove, :autosave, :validate, :join_table, :class_name, :extend, :strict_loading, :deprecated].each do |k|
20392039
hm_options[k] = options[k] if options.key?(k)
20402040
end
20412041

activerecord/lib/active_record/reflection.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,19 +1217,6 @@ def add_as_through(seed)
12171217
collect_join_reflections(seed + [self])
12181218
end
12191219

1220-
def deprecated?
1221-
unless defined?(@deprecated)
1222-
@deprecated =
1223-
if parent_reflection.is_a?(HasAndBelongsToManyReflection)
1224-
parent_reflection.deprecated?
1225-
else
1226-
delegate_reflection.deprecated?
1227-
end
1228-
end
1229-
1230-
@deprecated
1231-
end
1232-
12331220
def deprecated_nested_reflections
12341221
@deprecated_nested_reflections ||= collect_deprecated_nested_reflections
12351222
end

0 commit comments

Comments
 (0)