diff options
| author | Alban Peignier | 2016-11-15 19:06:42 +0100 |
|---|---|---|
| committer | Alban Peignier | 2016-11-15 19:07:43 +0100 |
| commit | e01de06d112269a38064b9bfee6774bcc9ad92ea (patch) | |
| tree | c61dd7a72e73560b3796fff5d9133270f3f4d139 | |
| parent | a98e911bb6f60b9414b9608e1fcd61561f033d0a (diff) | |
| download | chouette-core-e01de06d112269a38064b9bfee6774bcc9ad92ea.tar.bz2 | |
Patch PostgreSQLColumn.array_to_string to fix syntax of range array. Refs #1782
| -rw-r--r-- | config/initializers/postgresql_adapter_patch.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/config/initializers/postgresql_adapter_patch.rb b/config/initializers/postgresql_adapter_patch.rb index ae228f62f..6284c80ed 100644 --- a/config/initializers/postgresql_adapter_patch.rb +++ b/config/initializers/postgresql_adapter_patch.rb @@ -10,3 +10,28 @@ # end # end # ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:primary_key] = "bigserial primary key" + +# Add missing double-quote to write array of daterange in SQL query +# See #1782 + +class ActiveRecord::ConnectionAdapters::PostgreSQLColumn + + def self.array_to_string(value, column, adapter) + casted_values = value.map do |val| + if String === val + if val == "NULL" + "\"#{val}\"" + else + quote_and_escape(adapter.type_cast(val, column, true)) + end + elsif Range === val + casted_value = adapter.type_cast(val, column, true) + "\"#{casted_value}\"" + else + adapter.type_cast(val, column, true) + end + end + "{#{casted_values.join(',')}}" + end + +end |
