123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::TableMetadata

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: activerecord/lib/active_record/table_metadata.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(klass, arel_table, reflection = nil) ⇒ TableMetadata

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 7

def initialize(klass, arel_table, reflection = nil)
  @klass = klass
  @arel_table = arel_table
  @reflection = reflection
end

Instance Attribute Details

#arel_table (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 78

attr_reader :arel_table

#join_foreign_key (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 5

delegate :join_primary_key, :join_primary_type, :join_foreign_key, :join_foreign_type, to: :reflection

#join_foreign_type (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 5

delegate :join_primary_key, :join_primary_type, :join_foreign_key, :join_foreign_type, to: :reflection

#join_primary_key (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 5

delegate :join_primary_key, :join_primary_type, :join_foreign_key, :join_foreign_type, to: :reflection

#join_primary_type (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 5

delegate :join_primary_key, :join_primary_type, :join_foreign_key, :join_foreign_type, to: :reflection

#klass (readonly, private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 81

attr_reader :klass, :reflection

#polymorphic_association?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 53

def polymorphic_association?
  reflection&.polymorphic?
end

#reflection (readonly, private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 81

attr_reader :klass, :reflection

#through_association?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 61

def through_association?
  reflection&.through_reflection?
end

Instance Method Details

#aggregated_with?(aggregation_name)

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 68

alias :aggregated_with? :reflect_on_aggregation

#associated_table(table_name)

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 29

def associated_table(table_name)
  reflection = klass._reflect_on_association(table_name) || klass._reflect_on_association(table_name.singularize)

  if !reflection && table_name == arel_table.name
    return self
  end

  if reflection
    association_klass = reflection.klass unless reflection.polymorphic?
  elsif block_given?
    association_klass = yield table_name
  end

  if association_klass
    arel_table = association_klass.arel_table
    arel_table = arel_table.alias(table_name) if arel_table.name != table_name
    TableMetadata.new(association_klass, arel_table, reflection)
  else
    type_caster = TypeCaster::Connection.new(klass, table_name)
    arel_table = Arel::Table.new(table_name, type_caster: type_caster)
    TableMetadata.new(nil, arel_table, reflection)
  end
end

#associated_with?(table_name) ⇒ Boolean

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 25

def associated_with?(table_name)
  klass&._reflect_on_association(table_name)
end

#has_column?(column_name) ⇒ Boolean

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 21

def has_column?(column_name)
  klass&.columns_hash&.key?(column_name)
end

#polymorphic_name_association

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 57

def polymorphic_name_association
  reflection&.polymorphic_name
end

#predicate_builder

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 70

def predicate_builder
  if klass
    klass.predicate_builder.with(self)
  else
    PredicateBuilder.new(self)
  end
end

#primary_key

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 13

def primary_key
  klass&.primary_key
end

#reflect_on_aggregation(aggregation_name) Also known as: #aggregated_with?

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 65

def reflect_on_aggregation(aggregation_name)
  klass&.reflect_on_aggregation(aggregation_name)
end

#type(column_name)

[ GitHub ]

  
# File 'activerecord/lib/active_record/table_metadata.rb', line 17

def type(column_name)
  arel_table.type_for_attribute(column_name)
end