instance method
column_exists?
Ruby on Rails 3.1.12
Since v3.0.20Signature
column_exists?(table_name, column_name, type = nil, options = {})
Checks to see if a column exists in a given table.
Examples
# Check a column exists column_exists?(:suppliers, :name) # Check a column exists of a particular type column_exists?(:suppliers, :name, :string) # Check a column exists with a specific definition column_exists?(:suppliers, :name, :string, :limit => 100)
Parameters
-
table_namereq -
column_namereq -
typeopt = nil -
optionsopt = {}
Source
# File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 70
def column_exists?(table_name, column_name, type = nil, options = {})
columns(table_name).any?{ |c| c.name == column_name.to_s &&
(!type || c.type == type) &&
(!options[:limit] || c.limit == options[:limit]) &&
(!options[:precision] || c.precision == options[:precision]) &&
(!options[:scale] || c.scale == options[:scale]) }
end
Defined in activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb line 70
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::ConnectionAdapters::SchemaStatements