Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-1484

Include Relation into Mongoid Document

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.4.0
    • Affects Version/s: None
    • Component/s: None

      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")
      => #<Ak::Screen _id: 4ede339fa9dfe1122f000001, version_id:
      BSON::ObjectId('4eddfa34a9dfe10f86000001')>

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

      WidgetScreen.new(version_id: "4eddfa34a9dfe10f86000001")
      => #<Ak::Screen _id: 4ede339fa9dfe1122f000001, version_id:
      "4eddfa34a9dfe10f86000001">

            Assignee:
            Unassigned Unassigned
            Reporter:
            cyrez cyrez
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: