mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Rename target_klass to klass
This commit is contained in:
parent
8b00da5258
commit
a5274bb52c
3 changed files with 10 additions and 10 deletions
|
@ -19,7 +19,7 @@ module ActiveRecord
|
||||||
class Association #:nodoc:
|
class Association #:nodoc:
|
||||||
attr_reader :owner, :target, :reflection
|
attr_reader :owner, :target, :reflection
|
||||||
|
|
||||||
delegate :options, :klass, :to => :reflection
|
delegate :options, :to => :reflection
|
||||||
|
|
||||||
def initialize(owner, reflection)
|
def initialize(owner, reflection)
|
||||||
reflection.check_validity!
|
reflection.check_validity!
|
||||||
|
@ -93,11 +93,11 @@ module ActiveRecord
|
||||||
# by scope.scoping { ... } or with_scope { ... } etc, which affects the scope which
|
# by scope.scoping { ... } or with_scope { ... } etc, which affects the scope which
|
||||||
# actually gets built.
|
# actually gets built.
|
||||||
def construct_scope
|
def construct_scope
|
||||||
@association_scope = association_scope if target_klass
|
@association_scope = association_scope if klass
|
||||||
end
|
end
|
||||||
|
|
||||||
def association_scope
|
def association_scope
|
||||||
scope = target_klass.unscoped
|
scope = klass.unscoped
|
||||||
scope = scope.create_with(creation_attributes)
|
scope = scope.create_with(creation_attributes)
|
||||||
scope = scope.apply_finder_options(options.slice(:readonly, :include))
|
scope = scope.apply_finder_options(options.slice(:readonly, :include))
|
||||||
scope = scope.where(interpolate(options[:conditions]))
|
scope = scope.where(interpolate(options[:conditions]))
|
||||||
|
@ -109,7 +109,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def aliased_table
|
def aliased_table
|
||||||
target_klass.arel_table
|
klass.arel_table
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set the inverse association, if possible
|
# Set the inverse association, if possible
|
||||||
|
@ -122,14 +122,14 @@ module ActiveRecord
|
||||||
|
|
||||||
# This class of the target. belongs_to polymorphic overrides this to look at the
|
# This class of the target. belongs_to polymorphic overrides this to look at the
|
||||||
# polymorphic_type field on the owner.
|
# polymorphic_type field on the owner.
|
||||||
def target_klass
|
def klass
|
||||||
reflection.klass
|
reflection.klass
|
||||||
end
|
end
|
||||||
|
|
||||||
# Can be overridden (i.e. in ThroughAssociation) to merge in other scopes (i.e. the
|
# Can be overridden (i.e. in ThroughAssociation) to merge in other scopes (i.e. the
|
||||||
# through association's scope)
|
# through association's scope)
|
||||||
def target_scope
|
def target_scope
|
||||||
target_klass.scoped
|
klass.scoped
|
||||||
end
|
end
|
||||||
|
|
||||||
# Loads the \target if needed and returns it.
|
# Loads the \target if needed and returns it.
|
||||||
|
@ -163,7 +163,7 @@ module ActiveRecord
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_target?
|
def find_target?
|
||||||
!loaded? && (!owner.new_record? || foreign_key_present?) && target_klass
|
!loaded? && (!owner.new_record? || foreign_key_present?) && klass
|
||||||
end
|
end
|
||||||
|
|
||||||
def interpolate(sql, record = nil)
|
def interpolate(sql, record = nil)
|
||||||
|
|
|
@ -29,7 +29,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
if foreign_key_present?
|
if foreign_key_present?
|
||||||
target_klass.decrement_counter(counter_cache_name, target_id)
|
klass.decrement_counter(counter_cache_name, target_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,14 +10,14 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def different_target?(record)
|
def different_target?(record)
|
||||||
super || record.class != target_klass
|
super || record.class != klass
|
||||||
end
|
end
|
||||||
|
|
||||||
def inverse_reflection_for(record)
|
def inverse_reflection_for(record)
|
||||||
reflection.polymorphic_inverse_of(record.class)
|
reflection.polymorphic_inverse_of(record.class)
|
||||||
end
|
end
|
||||||
|
|
||||||
def target_klass
|
def klass
|
||||||
type = owner[reflection.foreign_type]
|
type = owner[reflection.foreign_type]
|
||||||
type && type.constantize
|
type && type.constantize
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue