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, slot: 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
deprecated
Internal use only
Deprecated.
use auto_populated_on_insert? instead
- #auto_populated_on_insert? ⇒ Boolean readonly Internal use only
- #auto_populated_on_update? ⇒ Boolean readonly Internal use only
- #bigint? ⇒ Boolean readonly Internal use only
- #cast_type 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
- #slot readonly Internal use only
- #sql_type_metadata readonly Internal use only
- #virtual? ⇒ Boolean readonly Internal use only
Instance Method Summary
-
#==(other)
(also: #eql?)
Internal use only
: (untyped) -> bool.
- #as_schema_json Internal use only
-
#encode_with(coder)
Internal use only
: (Psych::Coder | Hash[String, untyped]) -> void.
-
#eql?(other)
Internal use only
Alias for #==.
-
#hash
Internal use only
: () ->
::Integer. -
#human_name
Internal use only
Returns the human name of the column name.
- #init_from_schema_json(coder, references) Internal use only
-
#init_with(coder)
Internal use only
: (Psych::Coder | Hash[String, untyped]) -> void.
- #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, slot: nil) ⇒ Column
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.
#slot is the column's position in the table, starting at 0.
: (String, ::ActiveModel::Type::Value, untyped, ?untyped, ?bool, ?String?, ?collation: String?, ?comment: String?, ?slot: Integer?, **untyped) -> void
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 22
def initialize(name, cast_type, default, = nil, null = true, default_function = nil, collation: nil, comment: nil, slot: nil, **) @name = name.freeze @cast_type = cast_type @sql_type_metadata = @null = null @default = default @default_function = default_function @collation = collation @comment = comment @slot = slot end
Instance Attribute Details
#auto_incremented_by_db? ⇒ Boolean (readonly)
whether the column is auto-populated by the database using a sequence
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 92
def auto_incremented_by_db? false end
#auto_populated? ⇒ Boolean (readonly)
use auto_populated_on_insert? instead
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 100
def auto_populated? auto_populated_on_insert? end
#auto_populated_on_insert? ⇒ Boolean (readonly)
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 96
def auto_populated_on_insert? auto_incremented_by_db? || default_function end
#auto_populated_on_update? ⇒ Boolean (readonly)
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 105
def auto_populated_on_update? virtual? end
#bigint? ⇒ Boolean (readonly)
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 38
def bigint? /\Abigint\b/.match?(sql_type) end
#cast_type (readonly)
#collation (readonly)
#comment (readonly)
#default (readonly)
#default_function (readonly)
#has_default? ⇒ Boolean (readonly)
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 34
def has_default? !default.nil? || default_function end
#limit (readonly)
[ GitHub ]#name (readonly)
#null (readonly)
#precision (readonly)
[ GitHub ]#scale (readonly)
[ GitHub ]#slot (readonly)
#sql_type (readonly)
[ GitHub ]#sql_type_metadata (readonly)
#type (readonly)
[ GitHub ]
#virtual? ⇒ Boolean (readonly)
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 141
def virtual? false end
Instance Method Details
#==(other) Also known as: #eql?
: (untyped) -> bool
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 110
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 && slot == other.slot end
#as_schema_json
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 79
def as_schema_json data = {} encode_with(data) data end
#deduplicated (private)
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 146
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)
: (Psych::Coder | Hash[String, untyped]) -> void
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 67
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 coder["slot"] = @slot end
#eql?(other)
Alias for #==.
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 122
alias :eql? :==
#hash
: () -> ::Integer
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 125
def hash [ Column, @name, @name.encoding, @cast_type, @default, @sql_type_metadata, @null, @default_function, @collation, @comment, @slot, ].hash end
#human_name
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 49
def human_name Base.human_attribute_name(@name) end
#init_from_schema_json(coder, references)
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 85
def init_from_schema_json(coder, references) init_with(coder) @cast_type = references[@cast_type] if @cast_type @sql_type_metadata = references[@sql_type_metadata] if @sql_type_metadata end
#init_with(coder)
: (Psych::Coder | Hash[String, untyped]) -> void
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 54
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"] @slot = coder["slot"] end