mongoid/mongoid — Issue #1483: Include Relation into Mongoid Document 
Author: cyrez
Created: 2011-12-07 09:01:51+00:00
State: open

I have a Gem with an Mongoid Document "Ak::Screen" and a Rails
Application which uses this Gem. In the Rails Application i have the
Mongoid Documents "ScreenVersion" and "WidgetScreen" which inherits
from Ak::Screen. Now i want to add the following Relation between
this Documents: Screen n------1 ScreenVersion

module Screen
extend ActiveSupport::Concern
included do
belongs_to :presentable_version
end
end

Ak::Screen.send :include, Screen

(i simpliefied this example, maybe there are problems with the
namespaces now)

Everything works fine so far. I can call WidgetScreen.first.versions
for example..

Problem:

This works:

Ak::Screen.new(version_id: "4eddfa34a9dfe10f86000001")
=> #

The inherited Document doesn't convert the version_id to
BSON::ObjectId:

WidgetScreen.new(version_id: "4eddfa34a9dfe10f86000001")
=> #