Class: ActiveRecord::ConnectionAdapters::Column
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
Deduplicable
|
|
Inherits: | Object |
Defined in: | activerecord/lib/active_record/connection_adapters/column.rb |
Overview
An abstract definition of a column in a table.
Class Method Summary
-
.new(name, cast_type, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil) ⇒ Column
constructor
Internal use only
Instantiates a new column in the table.
Instance Attribute Summary
- #limit readonly
- #precision readonly
- #scale readonly
- #sql_type readonly
- #type readonly
-
#auto_incremented_by_db? ⇒ Boolean
readonly
Internal use only
whether the column is auto-populated by the database using a sequence.
- #auto_populated? ⇒ Boolean readonly Internal use only
- #bigint? ⇒ Boolean readonly Internal use only
- #collation readonly Internal use only
- #comment readonly Internal use only
- #default readonly Internal use only
- #default_function readonly Internal use only
- #has_default? ⇒ Boolean readonly Internal use only
- #name readonly Internal use only
- #null readonly Internal use only
- #sql_type_metadata readonly Internal use only
- #virtual? ⇒ Boolean readonly Internal use only
- #cast_type readonly protected Internal use only
Instance Method Summary
- #==(other) (also: #eql?) Internal use only
- #encode_with(coder) Internal use only
-
#eql?(other)
Internal use only
Alias for #==.
- #fetch_cast_type(connection) Internal use only
- #hash Internal use only
-
#human_name
Internal use only
Returns the human name of the column name.
- #init_with(coder) Internal use only
- #deduplicated private Internal use only
Deduplicable
- Included
#-@ | Alias for Deduplicable#deduplicate. |
#deduplicate, #deduplicated |
Constructor Details
.new(name, cast_type, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil) ⇒ Column
This method is for internal use only.
Instantiates a new column in the table.
#name is the column’s name, such as supplier_id
in supplier_id bigint
. #default is the type-casted default value, such as new
in sales_stage varchar(20) default 'new'
. #sql_type_metadata is various information about the type of the column #null determines if this column allows NULL
values.
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 20
def initialize(name, cast_type, default, = nil, null = true, default_function = nil, collation: nil, comment: nil, **) @name = name.freeze @cast_type = cast_type @sql_type_metadata = @null = null @default = default.nil? || cast_type.mutable? ? default : cast_type.deserialize(default) @default_function = default_function @collation = collation @comment = comment end
Instance Attribute Details
#auto_incremented_by_db? ⇒ Boolean
(readonly)
This method is for internal use only.
whether the column is auto-populated by the database using a sequence
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 75
def auto_incremented_by_db? false end
#auto_populated? ⇒ Boolean
(readonly)
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 79
def auto_populated? auto_incremented_by_db? || default_function end
#bigint? ⇒ Boolean
(readonly)
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 40
def bigint? /\Abigint\b/.match?(sql_type) end
#cast_type (readonly, protected)
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 114
attr_reader :cast_type
#collation (readonly)
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10
attr_reader :name, :default, :, :null, :default_function, :collation, :comment
#comment (readonly)
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10
attr_reader :name, :default, :, :null, :default_function, :collation, :comment
#default (readonly)
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10
attr_reader :name, :default, :, :null, :default_function, :collation, :comment
#default_function (readonly)
This method is for internal use only.
[ GitHub ]
#has_default? ⇒ Boolean
(readonly)
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 36
def has_default? !default.nil? || default_function end
#limit (readonly)
[ GitHub ]#name (readonly)
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10
attr_reader :name, :default, :, :null, :default_function, :collation, :comment
#null (readonly)
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10
attr_reader :name, :default, :, :null, :default_function, :collation, :comment
#precision (readonly)
[ GitHub ]#scale (readonly)
[ GitHub ]#sql_type (readonly)
[ GitHub ]#sql_type_metadata (readonly)
This method is for internal use only.
[ GitHub ]
#type (readonly)
[ GitHub ]
#virtual? ⇒ Boolean
(readonly)
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 109
def virtual? false end
Instance Method Details
#==(other) Also known as: #eql?
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 83
def ==(other) other.is_a?(Column) && name == other.name && cast_type == other.cast_type && default == other.default && == other. && null == other.null && default_function == other.default_function && collation == other.collation && comment == other.comment end
#deduplicated (private)
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 117
def deduplicated @name = -name @sql_type_metadata = .deduplicate if @default = -default if String === default @default_function = -default_function if default_function @collation = -collation if collation @comment = -comment if comment super end
#encode_with(coder)
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 63
def encode_with(coder) coder["name"] = @name coder["cast_type"] = @cast_type coder["sql_type_metadata"] = @sql_type_metadata coder["null"] = @null coder["default"] = @default coder["default_function"] = @default_function coder["collation"] = @collation coder["comment"] = @comment end
#eql?(other)
This method is for internal use only.
Alias for #==.
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 94
alias :eql? :==
#fetch_cast_type(connection)
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 31
def fetch_cast_type(connection) # :nodoc: # TODO: Remove fetch_cast_type and the need for connection after we release 8.1. @cast_type || connection.lookup_cast_type(sql_type) end
#hash
This method is for internal use only.
[ GitHub ]
#human_name
This method is for internal use only.
Returns the human name of the column name.
Examples
Column.new('sales_stage', ...).human_name # => 'Sales stage'
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 48
def human_name Base.human_attribute_name(@name) end
#init_with(coder)
This method is for internal use only.
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 52
def init_with(coder) @name = coder["name"] @cast_type = coder["cast_type"] @sql_type_metadata = coder["sql_type_metadata"] @null = coder["null"] @default = coder["default"] @default_function = coder["default_function"] @collation = coder["collation"] @comment = coder["comment"] end