Class: ActiveRecord::Reflection::BelongsToReflection

Inherits:
AssociationReflection show all
Defined in:
activerecord/lib/active_record/reflection.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from AssociationReflection

#foreign_type, #parent_reflection, #type

Attributes inherited from MacroReflection

#active_record, #name, #options, #plural_name, #scope

Instance Method Summary collapse

Methods inherited from AssociationReflection

#active_record_primary_key, #add_as_polymorphic_through, #add_as_source, #add_as_through, #association_foreign_key, #association_scope_cache, #check_eager_loadable!, #check_validity!, #clear_association_scope_cache, #collect_join_chain, #collection?, #compute_class, #extensions, #foreign_key, #has_inverse?, #has_one?, #has_scope?, #initialize, #join_id_for, #join_table, #nested?, #polymorphic?, #polymorphic_inverse_of, #source_reflection, #through_reflection, #validate?

Methods inherited from MacroReflection

#==, #autosave=, #compute_class, #initialize, #klass, #scope_for

Methods inherited from AbstractReflection

#alias_candidate, #build_association, #build_scope, #chain, #check_validity_of_inverse!, #class_name, #constraints, #counter_cache_column, #counter_must_be_updated_by_has_many?, #has_cached_counter?, #inverse_of, #inverse_updates_counter_in_memory?, #inverse_which_updates_counter_cache, #join_scope, #join_scopes, #klass_join_scope, #scopes, #strict_loading?, #strict_loading_violation_message, #table_name, #through_reflection?

Constructor Details

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

Instance Method Details

#association_classObject


731
732
733
734
735
736
737
# File 'activerecord/lib/active_record/reflection.rb', line 731

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

#association_primary_key(klass = nil) ⇒ Object

klass option is necessary to support loading polymorphic associations


740
741
742
743
744
745
746
# File 'activerecord/lib/active_record/reflection.rb', line 740

def association_primary_key(klass = nil)
  if primary_key = options[:primary_key]
    @association_primary_key ||= -primary_key.to_s
  else
    primary_key(klass || self.klass)
  end
end

#belongs_to?Boolean

Returns:

  • (Boolean)

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

def belongs_to?; true; end

#join_foreign_keyObject


752
753
754
# File 'activerecord/lib/active_record/reflection.rb', line 752

def join_foreign_key
  foreign_key
end

#join_foreign_typeObject


756
757
758
# File 'activerecord/lib/active_record/reflection.rb', line 756

def join_foreign_type
  foreign_type
end

#join_primary_key(klass = nil) ⇒ Object


748
749
750
# File 'activerecord/lib/active_record/reflection.rb', line 748

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

#macroObject


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

def macro; :belongs_to; end