// build mapping name: 'custom_entity_blog_products' => use field name instead of reference entity name to allow multiple references to same entity
$mappingName =
implode('_',
[$entityName,
$field['name'
]]);
// create many-to-many association field for custom entity definition
$association =
new ManyToManyAssociationField($property,
$field['reference'
],
$mappingName,
$entityName . '_id',
$field['reference'
] . '_id', 'id', 'id'
);
// mapping table records can always be deleted
$association->
addFlags(new CascadeDelete());
// field is maybe flag to be store-api aware
self::
addFlag($association,
$apiAware);
// check product inheritance and add ReverseInherited(reverse-property-name)
if ($reference->
isInheritanceAware() &&
$inherited) { $association->
addFlags(new ReverseInherited(self::
kebabCaseToCamelCase($mappingName)));
} // association for custom entity definition: done
$collection->
add($association);
// define mapping entity definition, fields are defined inside the definition class
$definition = DynamicMappingEntityDefinition::
create($entityName,
$field['reference'
],
$mappingName);