Motor-ODM icon indicating copy to clipboard operation
Motor-ODM copied to clipboard

Polymorphic Models

Open codello opened this issue 4 years ago • 0 comments

Mongo collections can contain documents of different shapes. Polymorphic models implement support for having multiple models in one collection. This comes with the following restrictions:

  • The Collection name must be declared on the “root” polymorphic model.
  • Each document has a “_type” associated with it that contains the model class name. By enabling the option “qualified_names” the full qualified class names will be used.
  • On instantiation the Model tries to create an instance of the respective type (by checking its known subclasses). If no such type exists an error is raised.
  • It is an error to mark a submodel of a polymorphic model as polymorphic as well.

Polymorphic models and abstract models can be combined.

codello avatar Apr 06 '20 11:04 codello