Well, I really don't want things that could be incredibly important being fudged in my data. Especially now that I have another dimension I can query on. So I "fixed" the object data type for when I'm working with CouchDB. This will allow you to both store and read values such as arrays and/or hashes without any voodoo. Just drop this override in your init.rb or in another place where it's sure to be loaded AFTER datamapper has been initialized.
module DataMapper
module Types
class Object < DataMapper::Type
primitive String
size 65535
lazy true
track :hash
def self.dump(value, property)
value.to_json unless value.nil?
end
def self.load(value, property)
value.nil? ? nil : value
end
end
end
end
No comments:
Post a Comment