# File lib/active_scaffold/data_structures/association/abstract.rb, line 63 def primary_key @association.options[:primary_key] end
class ActiveScaffold::DataStructures::Association::Abstract
Attributes
Public Class Methods
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 3 def initialize(association) @association = association end
Public Instance Methods
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 11 def allow_join? !polymorphic? end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 85 def as; end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 23 def belongs_to? @association.macro == :belongs_to end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 124 def cache_count? collection? && !ActiveScaffold::OrmChecks.tableless?(klass) && !reverse_association&.counter_cache end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 43 def collection? has_many? || habtm? end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 67 def counter_cache @association.options[:counter_cache] end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 91 def counter_cache_hack? false end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 35 def habtm? @association.macro == :has_and_belongs_to_many end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 31 def has_many? # rubocop:disable Naming/PredicateName @association.macro == :has_many end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 27 def has_one? # rubocop:disable Naming/PredicateName @association.macro == :has_one end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 108 def inverse_for?(klass) inverse_class = reverse_association(klass)&.inverse_klass inverse_class.present? && (inverse_class == klass || klass < inverse_class) end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 15 def klass(record = nil) if polymorphic? record&.send(foreign_type)&.safe_constantize else @association.klass end end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 51 def nested? false end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 71 def polymorphic? false end
Source
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 99 def quoted_primary_key raise "define quoted_primary_key method in #{self.class.name} class" end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 95 def quoted_table_name raise "define quoted_table_name method in #{self.class.name} class" end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 75 def readonly? false end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 87 def respond_to_target? false end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 103 def reverse(klass = nil) @reverse ||= inverse || get_reverse&.name unless polymorphic? @reverse || get_reverse(klass)&.name end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 113 def reverse_association(klass = nil) assoc = if polymorphic? get_reverse(klass) unless klass.nil? else reverse_name = reverse(klass) reflect_on_association(reverse_name) if reverse_name end self.class.new(assoc) if assoc end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 83 def scope; end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 39 def singular? !collection? end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 81 def source_reflection; end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 47 def through? false end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 59 def through_collection? through? && through_reflection.collection? end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 79 def through_reflection; end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 55 def through_singular? through? && !through_reflection.collection? end
Protected Instance Methods
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 134 def get_reverse(klass = nil) return nil if klass.nil? && polymorphic? # name-based matching (association name vs self.active_record.to_s) matches = reverse_matches(klass || self.klass) if matches.length > 1 matches.select! do |assoc| inverse_klass.name.underscore.include? assoc.name.to_s.pluralize.singularize end end matches.first end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 130 def reflect_on_association(name) @association.klass.reflect_on_association(name) end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 175 def reverse_direct_match?(assoc) # skip over has_and_belongs_to_many associations return false if assoc.macro == :has_and_belongs_to_many if foreign_key.is_a?(Array) || assoc.foreign_key.is_a?(Array) # composite_primary_keys assoc.foreign_key == foreign_key else assoc.foreign_key.to_sym == foreign_key.to_sym end end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 171 def reverse_habtm_match?(assoc) assoc.macro == :has_and_belongs_to_many end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 156 def reverse_match?(assoc) return assoc.name == as if as || assoc.polymorphic? return false if assoc.class_name != inverse_klass&.name if through? reverse_through_match?(assoc) elsif habtm? reverse_habtm_match?(assoc) else reverse_direct_match?(assoc) end end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 148 def reverse_matches(klass) associations = self.class.reflect_on_all_associations(klass) # collect associations that point back to this model and use the same foreign_key associations.each_with_object([]) do |assoc, reverse_matches| reverse_matches << assoc if assoc != @association && reverse_match?(assoc) end end
Source
# File lib/active_scaffold/data_structures/association/abstract.rb, line 169 def reverse_through_match?(assoc); end