From 5545f3c9432d3ef5043939ca6988265b0067c4ed Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Wed, 18 Mar 2009 13:30:30 -0400 Subject: [PATCH] new-style dbref for ruby enc/decoders --- lib/mongo/util/bson.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/mongo/util/bson.rb b/lib/mongo/util/bson.rb index 8d045ab..3127407 100644 --- a/lib/mongo/util/bson.rb +++ b/lib/mongo/util/bson.rb @@ -245,7 +245,12 @@ class BSON def deserialize_object_data(buf) size = buf.get_int buf.position -= 4 - BSON.new().deserialize(buf.get(size)) + object = BSON.new().deserialize(buf.get(size)) + if object.has_key? "$ref" + DBRef.new(object["$ref"], object["$id"]) + else + object + end end def deserialize_array_data(buf) @@ -324,8 +329,10 @@ class BSON end def serialize_dbref_element(buf, key, val) - serialize_string_element(buf, key, val.namespace, REF) - buf.put_array(val.object_id.to_a) + oh = OrderedHash.new + oh['$ref'] = val.namespace + oh['$id'] = val.object_id + serialize_object_element(buf, key, oh) end def serialize_binary_element(buf, key, val)