I've been searching for an answer on this issue, but couldn't find anything definitive. I ended up adding a method to my model to run a manual join. Here is what the code would look like in your example:
class Foo
include MongoMapper::Document
end
class Bar
include MongoMapper::Document
key :foo_id, ObjectId
def foo
Foo.find(foo_id)
end
def foo=(a_foo)
foo_id = a_foo.id
end
def serializable_hash(options = {})
hash = super(options)
hash.merge({'foo' => foo.serializable_hash})
end
end
foo = Foo.new
bar1 = Bar.new
bar1.foo = foo
bar2 = Bar.new
bar2.foo = foo
bar1.foo # Should return expected value