method
automatic_inverse_of
v7.1.3.2 -
Show latest stable
- Class:
ActiveRecord::Reflection::AssociationReflection
automatic_inverse_of()private
returns either nil or the inverse association name that it finds.
# File activerecord/lib/active_record/reflection.rb, line 708
def automatic_inverse_of
if can_find_inverse_of_automatically?(self)
inverse_name = ActiveSupport::Inflector.underscore(options[:as] || active_record.name.demodulize).to_sym
begin
reflection = klass._reflect_on_association(inverse_name)
rescue NameError => error
raise unless error.name.to_s == class_name
# Give up: we couldn't compute the klass type so we won't be able
# to find any associations either.
reflection = false
end
if valid_inverse_reflection?(reflection)
inverse_name
end
end
end Related methods
- Instance methods
- 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
- belongs_to?
- check_eager_loadable!
- check_validity!
- clear_association_scope_cache
- collect_join_chain
- collection?
- compute_class
- extensions
- foreign_key
- has_inverse?
- has_one?
- has_scope?
- join_foreign_key
- join_id_for
- join_primary_key
- join_primary_type
- join_table
- macro
- nested?
- polymorphic?
- polymorphic_inverse_of
- polymorphic_name
- source_reflection
- through_reflection
- validate?
- Class methods
- new
- Private methods
-
actual_source_reflection -
automatic_inverse_of -
can_find_inverse_of_automatically? -
collect_join_reflections -
constraints -
derive_class_name -
derive_fk_query_constraints -
derive_foreign_key -
inverse_name -
scope_allows_automatic_inverse_of? -
source_options -
source_reflection_name -
source_reflection_names -
through_options -
valid_inverse_reflection?