Skip to content

Instantly share code, notes, and snippets.

@rvalyi
Created September 15, 2015 15:00
Show Gist options
  • Save rvalyi/426777c7788321b8a6b4 to your computer and use it in GitHub Desktop.
Save rvalyi/426777c7788321b8a6b4 to your computer and use it in GitHub Desktop.
diff --git a/lib/ooor/persistence.rb b/lib/ooor/persistence.rb
index 18b2d02..1a55f3a 100644
--- a/lib/ooor/persistence.rb
+++ b/lib/ooor/persistence.rb
@@ -90,6 +90,9 @@ module Ooor
@attributes ||= {}
@loaded_associations = {}
attributes.each do |key, value|
+if key.to_s == "id"
+ @attributes['id'] = value
+end
self.send "#{key}=", value if self.respond_to?("#{key}=")
end
self
diff --git a/lib/ooor/type_casting.rb b/lib/ooor/type_casting.rb
index f2d2707..afd6afe 100644
--- a/lib/ooor/type_casting.rb
+++ b/lib/ooor/type_casting.rb
@@ -86,14 +86,27 @@ module Ooor
when 'date'
map[k] = Date.parse(v)
end
+ elsif v.is_a?(Hash)
+ map[k] = cast_map_to_ruby!(v)
+ elsif v.is_a?(Array)
+v.each {|item| self.cast_map_to_ruby!(item) if item.is_a? Hash}
end
end
end
if answer.is_a?(Array)
- answer.each {|item| self.cast_map_to_ruby!(item) if item.is_a? Hash}
+# answer.each {|item| self.cast_map_to_ruby!(item) if item.is_a? Hash}
+ answer.each do |item|
+#self.cast_map_to_ruby!(item) if item.is_a? Hash
+if item.is_a? Hash
+self.cast_map_to_ruby!(item)
+else
+end
+answer
+end
elsif answer.is_a?(Hash)
self.cast_map_to_ruby!(answer)
+answer
else
answer
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment