Skip to content

Commit 81d08f8

Browse files
prathamesh-sonpatkikares
authored andcommitted
Add support for XML as present in Rails 4.2 for PG
- This was done to not rely on sql_type for quoting xml values. Commit - rails/rails@f6968bd
1 parent 60d767d commit 81d08f8

File tree

1 file changed

+22
-0
lines changed
  • lib/arjdbc/postgresql/base

1 file changed

+22
-0
lines changed

lib/arjdbc/postgresql/base/oid.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,28 @@ def changed_in_place?(raw_old_value, new_value)
358358
super(raw_old_value, new_value)
359359
end
360360
end if ActiveRecord::VERSION.to_s >= '4.2'
361+
362+
class Xml < ActiveRecord::Type::String
363+
def type
364+
:xml
365+
end
366+
367+
def type_cast_for_database(value)
368+
return unless value
369+
Data.new(super)
370+
end
371+
372+
class Data # :nodoc:
373+
def initialize(value)
374+
@value = value
375+
end
376+
377+
def to_s
378+
@value
379+
end
380+
end
381+
end if ActiveRecord::VERSION.to_s >= '4.2'
382+
361383
class Uuid < Type
362384
def type; :uuid end
363385
def type_cast(value)

0 commit comments

Comments
 (0)