-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
I have a fairly standard model:
class Task
include Mongoid::Document
field :result, :type => Hash
...
I am having trouble saving certain values for the 'result' field. Yes, it is a Hash but my problem doesn't seem to do anything with deep copies as I'm updating the entire Hash.
So, here's what I did:
1.9.3p125 :154 > r = nil => nil 1.9.3p125 :155 > Task.last.update_attribute(:result, r); Task.last.result => nil 1.9.3p125 :156 > r = {"a title"=>["ABC"]} => {"a title"=>["ABC"]} 1.9.3p125 :157 > Task.last.update_attribute(:result, r); Task.last.result => {"a title"=>["ABC"]}
So far so good, right? Now, watch this:
1.9.3p125 :158 > r = {"my.title"=>["ABC"]} => {"my.title"=>["ABC"]} 1.9.3p125 :159 > Task.last.update_attribute(:result, r); Task.last.result => {"a title"=>["ABC"]}
As you can see, the last hash did not get saved at all.
Here's what the DB log looked like:
MONGODB (0ms) my_development['tasks'].update({"_id"=>BSON::ObjectId('4f96fe5a679d6bdf71000006')}, {"$set"=>{"result"=>nil, "updated_at"=>2012-04-24 19:43:12 UTC}}) MONGODB (0ms) my_development['tasks'].find({:deleted_at=>nil}).limit(-1).sort([[:_id, :desc]]) MONGODB (1ms) my_development['tasks'].find({:deleted_at=>nil}).limit(-1).sort([[:_id, :desc]]) MONGODB (0ms) my_development['tasks'].update({"_id"=>BSON::ObjectId('4f96fe5a679d6bdf71000006')}, {"$set"=>{"result"=>{"a title"=>["ABC"]}, "updated_at"=>2012-04-24 19:43:21 UTC}}) MONGODB (0ms) my_development['tasks'].find({:deleted_at=>nil}).limit(-1).sort([[:_id, :desc]]) MONGODB (0ms) my_development['tasks'].find({:deleted_at=>nil}).limit(-1).sort([[:_id, :desc]]) MONGODB (0ms) my_development['tasks'].update({"_id"=>BSON::ObjectId('4f96fe5a679d6bdf71000006')}, {"$set"=>{"result"=>{"my.title"=>["ABC"]}, "updated_at"=>2012-04-24 19:43:30 UTC}}) MONGODB (0ms) my_development['tasks'].find({:deleted_at=>nil}).limit(-1).sort([[:_id, :desc]])
Any thoughts? Is there a list of characters that are not serialized properly?