module SchemaPlus::Columns::ActiveRecord::ConnectionAdapters::Column

SchemaPlus::Index adds several methods to Column

Attributes

model[W]

Public Instance Methods

as_json(options=nil) click to toggle source

The default as_jon includes all instance variables. but @model can’t be dumped (it contains circular references)

# File lib/schema_plus/columns/active_record/connection_adapters/column.rb, line 50
def as_json(options=nil)
  instance_values.except "model", "adapter"
end
case_sensitive?() click to toggle source

Returns true if the column is in one or more indexes that are case sensitive. Will raise exception if IndexDefinition#case_sensitive? isn’t defined, i.e. if schema_plus_pg_indexes hasn’t been loaded.

# File lib/schema_plus/columns/active_record/connection_adapters/column.rb, line 44
def case_sensitive?
  indexes.any?{|i| i.case_sensitive?}
end
freeze() click to toggle source

AR 6.1+ freezes the columns. Temporary hack until I figure a better way to set the model

# File lib/schema_plus/columns/active_record/connection_adapters/column.rb, line 12
def freeze
  self
end
indexes() click to toggle source

Returns the list of IndexDefinition instances for each index that refers to this column. Returns an empty list if there are no such indexes.

# File lib/schema_plus/columns/active_record/connection_adapters/column.rb, line 21
def indexes
  @model.indexes.select{|index| index.columns.include? self.name}
end
required_on() click to toggle source

Returns the circumstance in which the column must have a value:

nil     if the column may be null
:save   if the column has no default value
:update otherwise
# File lib/schema_plus/columns/active_record/connection_adapters/column.rb, line 58
def required_on
  if null
    nil
  elsif default.nil?
    :save
  else
    :update
  end
end
unique?() click to toggle source

Returns true if the column is in a unique index. See also unique_scope

# File lib/schema_plus/columns/active_record/connection_adapters/column.rb, line 36
def unique?
  indexes.any?{|i| i.unique}
end
unique_scope() click to toggle source

If the column is in a unique index, returns a list of names of other columns in the index. Returns an empty list if it’s a single-column index. Returns nil if the column is not in a unique index.

# File lib/schema_plus/columns/active_record/connection_adapters/column.rb, line 28
def unique_scope
  if index = indexes.select{|i| i.unique}.sort_by{|i| i.columns.size}.first
    index.columns.reject{|name| name == self.name}
  end
end