123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::Reflection::BelongsToReflection

Do not use. This class is for internal use only.

Class Method Summary

Instance Attribute Summary

AssociationReflection - Inherited

#belongs_to?

Returns true if self is a belongs_to reflection.

#collection?

Returns whether or not this association reflection is for a collection association.

#foreign_type, #has_inverse?,
#has_one?

Returns true if self is a has_one reflection.

#has_scope?, #nested?,
#parent_reflection
#polymorphic?, #type,
#validate?

Returns whether or not the association should be validated as part of the parent’s validation.

MacroReflection - Inherited

#active_record, #autosave=,
#name

Returns the name of the macro.

#options

Returns the hash of options used for the macro.

#scope, #plural_name

AbstractReflection - Inherited

#counter_must_be_updated_by_has_many?,
#has_active_cached_counter?

Returns whether this association has a counter cache and its column values were backfilled (and so it is used internally by methods like size/any?/etc).

#has_cached_counter?

Returns whether this association has a counter cache.

#inverse_updates_counter_cache?
#inverse_updates_counter_in_memory?, #strict_loading?, #through_reflection?

Instance Method Summary

AssociationReflection - Inherited

#active_record_primary_key, #add_as_polymorphic_through, #add_as_source, #add_as_through, #association_class, #association_foreign_key, #association_primary_key, #association_scope_cache, #check_eager_loadable!, #check_validity!,
#clear_association_scope_cache

This is for clearing cache on the reflection.

#collect_join_chain

A chain of reflections from this one back to the owner.

#compute_class, #extensions, #foreign_key, #join_foreign_key, #join_id_for, #join_primary_key, #join_primary_type, #join_table,
#macro

Returns the macro type.

#polymorphic_inverse_of, #polymorphic_name, #source_reflection, #through_reflection,
#automatic_inverse_of

returns either nil or the inverse association name that it finds.

#can_find_inverse_of_automatically?

Checks to see if the reflection doesn’t have any options that prevent us from being able to guess the inverse automatically.

#derive_class_name, #derive_fk_query_constraints, #derive_foreign_key, #derive_join_table,
#inverse_name

Attempts to find the inverse association name automatically.

#scope_allows_automatic_inverse_of?

Scopes on the potential inverse reflection prevent automatic inverse_of, since the scope could exclude the owner record we would inverse from.

#valid_inverse_reflection?

Checks if the inverse reflection that is returned from the automatic_inverse_of method is a valid reflection.

MacroReflection - Inherited

#==

Returns true if self and other_aggregation have the same name attribute, active_record attribute, and other_aggregation has an options hash assigned to it.

#compute_class,
#klass

Returns the class for the macro.

#scope_for, #derive_class_name, #normalize_options, #_klass

AbstractReflection - Inherited

#alias_candidate,
#build_association

Returns a new, unsaved instance of the associated class.

#build_scope, #chain, #check_validity_of_inverse!,
#class_name

Returns the class name for the macro.

#constraints, #counter_cache_column, #inverse_of,
#inverse_which_updates_counter_cache

We need to avoid the following situation:

#join_scope, #join_scopes, #klass_join_scope,
#scopes

Returns a list of scopes that should be applied for this ::ActiveRecord::Reflection object when querying the database.

#strict_loading_violation_message, #table_name,
#actual_source_reflection

FIXME: this is a horrible name.

#ensure_option_not_given_as_class!, #primary_key

Constructor Details

This class inherits a constructor from ActiveRecord::Reflection::AssociationReflection

Instance Attribute Details

#belongs_to?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 915

def belongs_to?; true; end

Instance Method Details

#association_class

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 917

def association_class
  if polymorphic?
    Associations::BelongsToPolymorphicAssociation
  else
    Associations::BelongsToAssociation
  end
end

#association_primary_key(klass = nil)

klass option is necessary to support loading polymorphic associations

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 926

def association_primary_key(klass = nil)
  if primary_key = options[:primary_key]
    @association_primary_key ||= if primary_key.is_a?(Array)
      primary_key.map { |pk| pk.to_s.freeze }.freeze
    else
      -primary_key.to_s
    end
  elsif (klass || self.klass).has_query_constraints? || options[:query_constraints]
    (klass || self.klass).composite_query_constraints_list
  elsif (klass || self.klass).composite_primary_key?
    # If klass has composite primary key of shape [:<tenant_key>, :id], infer primary_key as :id
    primary_key = (klass || self.klass).primary_key
    primary_key.include?("id") ? "id" : primary_key
  else
    primary_key(klass || self.klass)
  end
end

#can_find_inverse_of_automatically?Boolean (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 957

def can_find_inverse_of_automatically?(*)
  !polymorphic? && super
end

#join_foreign_key

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 948

def join_foreign_key
  foreign_key
end

#join_foreign_type

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 952

def join_foreign_type
  foreign_type
end

#join_primary_key(klass = nil)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 944

def join_primary_key(klass = nil)
  polymorphic? ? association_primary_key(klass) : association_primary_key
end

#macro

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 913

def macro; :belongs_to; end