aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorDieter Komendera <dieter@komendera.com>2013-12-09 18:52:36 +0100
committerDieter Komendera <dieter@komendera.com>2014-03-04 10:32:20 +0100
commit5c55aafd38f45ac019573f98438ffdbdc8c580f9 (patch)
tree08cae090fc90789d286566ebe752f228ced0a9e0 /activerecord/lib/active_record
parentffcc6172b4d40ca7c8b02fd298c679b5bcf5787b (diff)
downloadrails-5c55aafd38f45ac019573f98438ffdbdc8c580f9.tar.gz
rails-5c55aafd38f45ac019573f98438ffdbdc8c580f9.tar.bz2
rails-5c55aafd38f45ac019573f98438ffdbdc8c580f9.zip
Add Enum type to postgresql adapter's oids to prevent unknown OID warnings.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb6
2 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
index e7df073627..697915f3e9 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
@@ -229,6 +229,12 @@ This is not reliable and will be removed in the future.
end
end
+ class Enum < Type
+ def type_cast(value)
+ value.to_s
+ end
+ end
+
class Hstore < Type
def type_cast_for_write(value)
ConnectionAdapters::PostgreSQLColumn.hstore_to_string value
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 9f18fdd3e5..a56ef91d07 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -801,6 +801,12 @@ module ActiveRecord
leaves, nodes = nodes.partition { |row| row['typelem'] == '0' }
arrays, nodes = nodes.partition { |row| row['typinput'] == 'array_in' }
+ # populate the enum types
+ enums, leaves = leaves.partition { |row| row['typinput'] == 'enum_in' }
+ enums.each do |row|
+ type_map[row['oid'].to_i] = OID::Enum.new
+ end
+
# populate the base types
leaves.find_all { |row| OID.registered_type? row['typname'] }.each do |row|
type_map[row['oid'].to_i] = OID::NAMES[row['typname']]