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
24 25 26 27 28 |
# File 'lib/active_record/mysql/enum/mysql_adapter.rb', line 24 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]
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/active_record/mysql/enum/mysql_adapter.rb', line 37 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 |