Session: How to Customize Collection Assignment for Entities
Entities are grouped into collections on the server side.
The name of the collection that an entity belongs to can be retrieved using the find_collection_name
convention.
Example
By default, a collection name is the pluralized form of a name of an entity type.
E.g., objects of type Category
will belong to the Categories
collection.
If you mean to classify them as ProductGroups
, however, use the following code:
def __find_collection_name(object_type: type) -> str:
if issubclass(object_type, Category):
return "ProductGroups"
return DocumentConventions.default_get_collection_name(object_type)
store.conventions.find_collection_name = __find_collection_name
This can become very useful when there is a need to deal with polymorphic data.