Session: How to Customize Collection Assignment for Entities
Entities are grouped on the server side into collections.
A collection's name is determined by the type of the entities in it.
To find the name of an entity's collection, use findCollectionName
.
Example
By default, a collection name is the pluralized form of an entity's type.
Entities of type Category
, for example, will belong to the Categories
collection.
To modify this behavior, use setFindCollectionName
.
$store->getConventions()->setFindCollectionName(function($className) {
if (is_subclass_of($className, Category::class)) {
return "ProductGroups";
}
return DocumentConventions::defaultGetCollectionName($className);
});
This can become very useful when there is a need to deal with polymorphic data.