Class: ActiveRecord::Reflection::BelongsToReflection
- Inherits:
-
AssociationReflection
- Object
- AbstractReflection
- MacroReflection
- AssociationReflection
- ActiveRecord::Reflection::BelongsToReflection
- Defined in:
- 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
- #association_class ⇒ Object
-
#association_primary_key(klass = nil) ⇒ Object
klass option is necessary to support loading polymorphic associations.
- #belongs_to? ⇒ Boolean
- #join_foreign_key ⇒ Object
- #join_foreign_type ⇒ Object
- #join_primary_key(klass = nil) ⇒ Object
- #macro ⇒ Object
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_primary_type, #join_table, #nested?, #polymorphic?, #polymorphic_inverse_of, #polymorphic_name, #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?, #initialize, #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_class ⇒ Object
863 864 865 866 867 868 869 |
# File 'lib/active_record/reflection.rb', line 863 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
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 |
# File 'lib/active_record/reflection.rb', line 872 def association_primary_key(klass = nil) if primary_key = [: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? || [: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 |
#belongs_to? ⇒ Boolean
861 |
# File 'lib/active_record/reflection.rb', line 861 def belongs_to?; true; end |
#join_foreign_key ⇒ Object
894 895 896 |
# File 'lib/active_record/reflection.rb', line 894 def join_foreign_key foreign_key end |
#join_foreign_type ⇒ Object
898 899 900 |
# File 'lib/active_record/reflection.rb', line 898 def join_foreign_type foreign_type end |
#join_primary_key(klass = nil) ⇒ Object
890 891 892 |
# File 'lib/active_record/reflection.rb', line 890 def join_primary_key(klass = nil) polymorphic? ? association_primary_key(klass) : association_primary_key end |
#macro ⇒ Object
859 |
# File 'lib/active_record/reflection.rb', line 859 def macro; :belongs_to; end |