Module: ActiveRecord::PGEnum::PostgreSQLAdapter
- Defined in:
- lib/active_record/pg_enum/postgresql_adapter.rb
Instance Method Summary collapse
-
#enum_types ⇒ Object
Helper method used by the monkeypatch internals.
Instance Method Details
#enum_types ⇒ Object
Helper method used by the monkeypatch internals. Provides a hash of ENUM types as they exist currently.
Example:
{ "foo_type" => ["foo", "bar", "baz"] }
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/active_record/pg_enum/postgresql_adapter.rb', line 9 def enum_types res = exec_query(" SELECT t.typname AS enum_name, string_agg(e.enumlabel, ' ' ORDER BY e.enumsortorder) AS enum_value\n FROM pg_type t\n JOIN pg_enum e ON t.oid = e.enumtypid\n JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n WHERE n.nspname = 'public'\n GROUP BY enum_name\n SQL\n\n res.inject({}) do |memo, (name, values)|\n memo[name] = values.split(\" \")\n memo\n end\nend\n".strip_heredoc, "SCHEMA").cast_values |