-
-
Save andikan/8618643 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module PgArrayHstoreFix | |
def self.included(base) | |
base.class_eval do | |
before_save :serialize_array_hash | |
end | |
def serialize_array_hash | |
self.class.attribute_names.each do |attribute| | |
column_definition = self.column_for_attribute(attribute) | |
if column_definition.array && column_definition.type == :hstore | |
serialized_hstore_array = [] | |
self.send(attribute.to_sym).each do |value| | |
serialized_hstore_array << value.to_s.gsub(/{|}/,'') | |
end | |
self.send("#{attribute}=".to_sym, serialized_hstore_array) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment