Module: ActiveRecord::Mysql::Enum::MysqlAdapter
- Defined in:
- lib/active_record/mysql/enum/mysql_adapter.rb
Instance Method Summary collapse
-
#native_database_types ⇒ Object
:nodoc.
-
#type_to_sql(type, limit: nil, **_options) ⇒ Object
Add enumeration support for schema statement creation.
Instance Method Details
#native_database_types ⇒ Object
:nodoc
18 19 20 21 22 |
# File 'lib/active_record/mysql/enum/mysql_adapter.rb', line 18 def native_database_types #:nodoc types = super types[:enum] = { :name => "enum" } types end |
#type_to_sql(type, limit: nil, **_options) ⇒ Object
Add enumeration support for schema statement creation. This will have to be adapted for every adapter if the type requires anything by a list of allowed values. The overrides the standard type_to_sql method and chains back to the default. This could be done on a per adapter basis, but is generalized here.
will generate enum('a', 'b', 'c') for :limit => [:a, :b, :c]
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_record/mysql/enum/mysql_adapter.rb', line 31 def type_to_sql(type, limit: nil, **) # :nodoc: if type.to_s == 'enum' column_type_sql = if (native_database_type = native_database_types[type]) native_database_type[:name] else 'enum' end quoted_values = limit.map { |v| quote(v) }.join(',') "#{column_type_sql}(#{quoted_values})" else super end end |