metadataPool = $metadataPool; $this->externalFKSetup = $externalFKSetup; } /** * {@inheritdoc} */ public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) { $installer = $setup; $installer->startSetup(); $listTables = [ 'report_viewed_product_aggregated_daily' => 'product_id', 'report_viewed_product_aggregated_monthly' => 'product_id', 'report_viewed_product_aggregated_yearly' => 'product_id', 'report_compared_product_index' => 'product_id', 'report_viewed_product_index' => 'product_id' ]; foreach ($listTables as $tableName => $columnName) { $this->addExternalForeignKeys($installer, $tableName, $columnName); } $installer->endSetup(); } /** * Add external foreign keys * * @param SchemaSetupInterface $installer * @param string $tableName * @param string $columnName * @return void * @throws \Exception */ protected function addExternalForeignKeys(SchemaSetupInterface $installer, $tableName, $columnName) { $metadata = $this->metadataPool->getMetadata(ProductInterface::class); $this->externalFKSetup->install( $installer, $metadata->getEntityTable(), $metadata->getIdentifierField(), $tableName, $columnName ); } }