Class: ActiveRecord::ConnectionAdapters::ReferenceDefinition
Do not use. This class is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb |
Class Method Summary
Instance Attribute Summary
- #foreign_key readonly private
- #index readonly private
- #name readonly private
- #options readonly private
- #polymorphic readonly private
- #type readonly private
Instance Method Summary
- #add(table_name, connection)
- #add_to(table)
- #as_options(value) private
- #column_name private
- #column_names private
- #columns private
- #conditional_options private
- #foreign_key_options private
- #foreign_table_name private
- #index_options(table_name) private
- #polymorphic_index_name(table_name) private
- #polymorphic_options private
Constructor Details
.new(name, polymorphic: false, index: true, foreign_key: false, type: :bigint, **options) ⇒ ReferenceDefinition
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 195
def initialize( name, polymorphic: false, index: true, foreign_key: false, type: :bigint, ** ) @name = name @polymorphic = polymorphic @index = index @foreign_key = foreign_key @type = type @options = if polymorphic && foreign_key raise ArgumentError, "Cannot add a foreign key to a polymorphic relation" end end
Instance Attribute Details
#foreign_key (readonly, private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 244
attr_reader :name, :polymorphic, :index, :foreign_key, :type, :
#index (readonly, private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 244
attr_reader :name, :polymorphic, :index, :foreign_key, :type, :
#name (readonly, private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 244
attr_reader :name, :polymorphic, :index, :foreign_key, :type, :
#options (readonly, private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 244
attr_reader :name, :polymorphic, :index, :foreign_key, :type, :
#polymorphic (readonly, private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 244
attr_reader :name, :polymorphic, :index, :foreign_key, :type, :
#type (readonly, private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 244
attr_reader :name, :polymorphic, :index, :foreign_key, :type, :
Instance Method Details
#add(table_name, connection)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 215
def add(table_name, connection) columns.each do |name, type, | connection.add_column(table_name, name, type, ** ) end if index connection.add_index(table_name, column_names, ** (table_name)) end if foreign_key connection.add_foreign_key(table_name, foreign_table_name, ** ) end end
#add_to(table)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 229
def add_to(table) columns.each do |name, type, | table.column(name, type, ** ) end if index table.index(column_names, ** (table.name)) end if foreign_key table.foreign_key(foreign_table_name, ** ) end end
#as_options(value) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 246
def (value) value.is_a?(Hash) ? value : {} end
#column_name (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 284
def column_name "#{name}_id" end
#column_names (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 288
def column_names columns.map(&:first) end
#columns (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 276
def columns result = [[column_name, type, ]] if polymorphic result.unshift(["#{name}_type", :string, ]) end result end
#conditional_options (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 250
def .slice(:if_exists, :if_not_exists) end
#foreign_key_options (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 272
def (foreign_key).merge(column: column_name, ** ) end
#foreign_table_name (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 292
def foreign_table_name .fetch(:to_table) do Base.pluralize_table_names ? name.to_s.pluralize : name end end
#index_options(table_name) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 262
def (table_name) = (index).merge( ) # legacy reference index names are used on versions 6.0 and earlier return if [:_uses_legacy_reference_index_name] [:name] ||= polymorphic_index_name(table_name) if polymorphic end
#polymorphic_index_name(table_name) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 258
def polymorphic_index_name(table_name) "index_#{table_name}_on_#{name}" end
#polymorphic_options (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 254
def (polymorphic).merge( ).merge( .slice(:null, :first, :after)) end