class ActiveScaffold::DataStructures::Association::ActiveRecord

Public Class Methods

reflect_on_all_associations(klass) click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 3
def self.reflect_on_all_associations(klass)
  klass.reflect_on_all_associations
end

Public Instance Methods

as() click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 33
def as
  @association.options[:as]
end
counter_cache_hack?() click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 58
def counter_cache_hack?
  belongs_to? && counter_cache && Rails.version < '6.0'
end
dependent() click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 37
def dependent
  @association.options[:dependent]
end
inverse() click to toggle source

name of inverse

# File lib/active_scaffold/data_structures/association/active_record.rb, line 42
def inverse
  @association.inverse_of&.name
end
inverse_klass() click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 29
def inverse_klass
  @association.active_record
end
quoted_primary_key() click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 50
def quoted_primary_key
  @association.klass.quoted_primary_key
end
quoted_table_name() click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 46
def quoted_table_name
  @association.klass.quoted_table_name
end
readonly?() click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 13
def readonly?
  scope_values[:readonly]
end
respond_to_target?() click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 54
def respond_to_target?
  true
end
scope() click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 25
def scope
  @association.scope
end
source_reflection() click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 21
def source_reflection
  @association.source_reflection if through?
end
through?() click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 9
def through?
  @association.options[:through].present?
end
through_reflection() click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 17
def through_reflection
  @association.through_reflection if through?
end

Protected Instance Methods

reverse_direct_match?(assoc) click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 81
def reverse_direct_match?(assoc)
  # skip over has_many :through associations
  !assoc.options[:through] && super
end
reverse_habtm_match?(assoc) click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 77
def reverse_habtm_match?(assoc)
  super && assoc.options[:join_table] == @association.options[:join_table]
end
reverse_through_match?(assoc) click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 73
def reverse_through_match?(assoc)
  assoc.options[:through] && assoc.through_reflection.class_name == through_reflection.class_name
end
scope_values() click to toggle source
# File lib/active_scaffold/data_structures/association/active_record.rb, line 64
def scope_values
  return {} unless @association.scope
  @scope_values ||= @association.klass.instance_exec(&@association.scope).values
rescue StandardError => e
  message = "Error evaluating scope for #{@association.name} in #{@association.klass.name}:"
  Rails.logger.warn "#{message}\n#{e.message}\n#{e.backtrace.join("\n")}"
  {}
end