rs-pro/mongoid-elasticsearch — pull request #2 by Antti (2013-12-07 11:54:55+00:00)
Title: Properly restore BSON::ObjectId from ES document using :model wrapper.

When you use :model wrapper, and it loads object attributes from ES to Mongoid model, it sets your association's id as {"$oid" => BSON::ObjectId()}, where it should just be BSON::ObjectId().

```ruby
my_object.inspect =>
# ... my_relation_id: {"$oid"=>BSON::ObjectId('529f85db616e640d58dcc300')} ...
```
So when you call your relation,you'll get an exception:

```ruby
my_object.my_relation
"invalid operator: $oid"
```

I think it's more Mongoid problem:
when you dump BSON::ObjectId you get {"$oid" => "abc012345"}, and you can not load it back as BSON::ObjectID using JSON.parse.
So we should do some workarounds, for example check if restored object is a hash with $oid and then intitalize BSON::ObjectId object for it.

Some related info
https://github.com/mongoid/mongoid/pull/2947