brocode/module-entityservices

magento2的实体服务

1.5.10 2023-05-02 05:16 UTC

This package is auto-updated.

Last update: 2024-08-31 00:33:23 UTC


README

  • 无需了解底层数组配置即可轻松更新数据库
  • 仅用几行代码即可创建新的EAV实体架构
  • 无需了解细微差别即可为产品、客户、分类添加EAV属性

###完成

  • 创建具有各种列、索引、外键的表
  • 为EAV实体创建一系列表
  • 更新表(添加/修改列、删除外键或索引)

###示例

在架构升级中的使用

class UpgradeSchema implements UpgradeSchemaInterface
   {
       /**
        * @var SchemaBuilder
        */
       private $schemaBuilderFactory;
   
       /**
        * UpgradeSchema constructor.
        * @param SchemaBuilder $schemaBuilderFactory
        */
       public function __construct(SchemaBuilderFactory $schemaBuilderFactory) {
   
           $this->schemaBuilderFactory = $schemaBuilderFactory;
       }
   
       public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
       {
           $setup->startSetup();
           if (version_compare($context->getVersion(), '1.1.0', '<')) {
               $this->schemaBuilderFactory->create($setup)->withTable('entity')
                   ->withIntColumn('entity_id')->asIdentiy()->asUnsigned()->asNullable(false)->asPrimaryKey()->build()
                   ->withVarcharColumn('field_id)->asNullable(false)->build()
                   ->withIndex(['field_id'])->build()
                   ->withForeignKey('field_id, 'other_table', 'other_column')->actionNoAction()->build()
                   ->build();
           }
           $setup->endSetup();
       }
   }