metadataPool = $metadataPool; $this->externalFKSetup = $externalFKSetup; } /** * {@inheritdoc} */ public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) { $installer = $setup; $installer->startSetup(); $listTables = [ ['product_alert_price', 'product_id'], ['product_alert_stock', 'product_id'], ]; foreach ($listTables as $tableData) { $this->addExternalForeignKeys($installer, $tableData[0], $tableData[1]); } $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 ); } }