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

Allow custom polymorphic types

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 9.0.2
    • Affects Version/s: None
    • Component/s: Persistence
    • Fully Compatible
    • Needed
    • Hide

      1. What would you like to communicate to the user about this feature?

      The description of the PR (here: https://github.com/mongodb/mongoid/pull/5845) includes a description of the way the code worked prior to this change, as well as a description of the API following this change.

      2. Would you like the user to see examples of the syntax and/or executable code and its output?

      Yes, please, per the examples given at the link mentioned above.

      3. Which versions of the driver/connector does this apply to?

      This applies to Mongoid 9.0.1 and later. (We are contemplating backporting to 8.1.x.)

      Show
      1. What would you like to communicate to the user about this feature? The description of the PR (here: https://github.com/mongodb/mongoid/pull/5845 ) includes a description of the way the code worked prior to this change, as well as a description of the API following this change. 2. Would you like the user to see examples of the syntax and/or executable code and its output? Yes, please, per the examples given at the link mentioned above. 3. Which versions of the driver/connector does this apply to? This applies to Mongoid 9.0.1 and later. (We are contemplating backporting to 8.1.x.)

      Mongoid supports polymorphism for has_one, has_many, embeds_one, and embeds_many. Current implementation stores parent actual class name in the child collection. For example, for this association belongs_to :unit, polymorphic: true the class name is stored in unit_type attribute.

      There is a demand to be able to infer the class name at runtime. See this article for example.

      We should allow storing arbitrary string in *_type attributes, and let the application code decide what is an actual class of the association's target.

            Assignee:
            jamis.buck@mongodb.com Jamis Buck
            Reporter:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: