`join_keys` no longer needs a class passed to it

Reflections only use their own information to create a `join_keys`
object.  This means that we can call `join_keys` on a reflection object
and have it be context-free.
上级 4be42720
......@@ -61,7 +61,7 @@ def join(table, constraint)
end
def last_chain_scope(scope, table, reflection, owner, association_klass)
join_keys = reflection.join_keys(association_klass)
join_keys = reflection.join_keys
key = join_keys.key
foreign_key = join_keys.foreign_key
......@@ -81,7 +81,7 @@ def transform_value(value)
end
def next_chain_scope(scope, table, reflection, association_klass, foreign_table, next_reflection)
join_keys = reflection.join_keys(association_klass)
join_keys = reflection.join_keys
key = join_keys.key
foreign_key = join_keys.foreign_key
......
......@@ -34,7 +34,7 @@ def join_constraints(foreign_table, foreign_klass, join_type, tables, chain)
table = tables.shift
klass = reflection.klass
join_keys = reflection.join_keys(klass)
join_keys = reflection.join_keys
key = join_keys.key
foreign_key = join_keys.foreign_key
......
......@@ -172,16 +172,8 @@ def class_name
JoinKeys = Struct.new(:key, :foreign_key) # :nodoc:
def join_keys(association_klass)
JoinKeys.new(join_pk(association_klass), join_fk)
end
def join_pk(klass)
foreign_key
end
def join_fk
active_record_primary_key
def join_keys
get_join_keys klass
end
# Returns a list of scopes that should be applied for this Reflection
......@@ -292,6 +284,20 @@ def alias_candidate(name)
def chain
collect_join_chain
end
def get_join_keys(association_klass)
JoinKeys.new(join_pk(association_klass), join_fk)
end
private
def join_pk(_)
foreign_key
end
def join_fk
active_record_primary_key
end
end
# Base class for AggregateReflection and AssociationReflection. Objects of
......@@ -719,14 +725,6 @@ def association_class
end
end
def join_fk
foreign_key
end
def join_pk(klass)
polymorphic? ? association_primary_key(klass) : association_primary_key
end
def join_id_for(owner) # :nodoc:
owner[foreign_key]
end
......@@ -736,6 +734,14 @@ def join_id_for(owner) # :nodoc:
def calculate_constructable(macro, options)
!polymorphic?
end
def join_fk
foreign_key
end
def join_pk(klass)
polymorphic? ? association_primary_key(klass) : association_primary_key
end
end
class HasAndBelongsToManyReflection < AssociationReflection # :nodoc:
......@@ -755,7 +761,7 @@ def collection?
class ThroughReflection < AbstractReflection #:nodoc:
attr_reader :delegate_reflection
delegate :foreign_key, :foreign_type, :association_foreign_key,
:active_record_primary_key, :type, to: :source_reflection
:active_record_primary_key, :type, :get_join_keys, to: :source_reflection
def initialize(delegate_reflection)
@delegate_reflection = delegate_reflection
......@@ -855,10 +861,6 @@ def has_scope?
through_reflection.has_scope?
end
def join_keys(association_klass)
source_reflection.join_keys(association_klass)
end
# A through association is nested if there would be more than one join table
def nested?
source_reflection.through_reflection? || through_reflection.through_reflection?
......@@ -993,6 +995,7 @@ def collect_join_reflections(seed)
end
private
def actual_source_reflection # FIXME: this is a horrible name
source_reflection.send(:actual_source_reflection)
end
......@@ -1054,10 +1057,6 @@ def plural_name
@reflection.plural_name
end
def join_keys(association_klass)
@reflection.join_keys(association_klass)
end
def type
@reflection.type
end
......@@ -1071,6 +1070,10 @@ def source_type_info
source_type = @previous_reflection.options[:source_type]
lambda { |object| where(type => source_type) }
end
def get_join_keys(association_klass)
@reflection.get_join_keys(association_klass)
end
end
class RuntimeReflection < PolymorphicReflection # :nodoc:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册