For multi store select you should not create a column in your table.
Because you are making a many to many relation between your entity and the store view entity you should have an extra table with the columns your_entity_id
and store_id
with foreign keys on both columns.
One to your main table and one to the store views table.
This way, if you delete your entity or a store view everything will cascade nicely and you won't end up with zombie data in your db.
The best core example you can use for this is the CMS module. Pick the pages or the static blocks as example.
TO create the table you need to do this in your upgrade schema
$installer = $setup;
if (version_compare($context->getVersion(), '1.0.2') < 0) {
$table = $installer->getConnection()->newTable(
$installer->getTable('adminsharan_adminsample_store')
)->addColumn(
'adminsample_id',
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
null,
['nullable' => false, 'primary' => true],
'Sample ID'
)->addColumn(
'store_id',
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
null,
['unsigned' => true, 'nullable' => false, 'primary' => true],
'Store ID'
)->addIndex(
$installer->getIdxName('adminsharan_adminsample_store', ['store_id']),
['store_id']
)->addForeignKey(
$installer->getFkName('adminsharan_adminsample_store', 'adminsample_id', 'adminsharan_adminsample', 'adminsample_id'),
'adminsample_id',
$installer->getTable('adminsharan_adminsample'),
'adminsample_id',
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
)->addForeignKey(
$installer->getFkName('adminsharan_adminsample_store', 'store_id', 'store', 'store_id'),
'store_id',
$installer->getTable('store'),
'store_id',
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
)->setComment(
'Sample To Store Linkage Table'
);
$installer->getConnection()->createTable($table);
}
And in order to insert and read data from that table once your entity is loaded take a look at the cms block resource model and check the methods that have something related to _store
tables and add them yo your entity resource model. Like _getLoadSelect
or lookupStoreIds
. There might be others also.
magento\vendor\magento\module-search\Setup\UpgradeSchema.php