]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Исправление миграций и добавление моделей
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 19 Nov 2024 09:14:19 +0000 (12:14 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 19 Nov 2024 09:14:19 +0000 (12:14 +0300)
erp24/migrations/m241102_124933_create_product_1c_prop_type_table.php
erp24/migrations/m241102_124956_create_product_1c_prop_value_table.php [deleted file]
erp24/migrations/m241102_124956_create_products_1c_additional_characteristics_table.php [new file with mode: 0644]
erp24/records/Product1cPropType.php [new file with mode: 0644]
erp24/records/Products1cAdditionalCharacteristics.php [new file with mode: 0644]

index 97cce87449a4f9c2f88c5b8cfd10faa24bae0cb3..e99444c4aaed221e01512a1b0ec42c17d519cd30 100644 (file)
@@ -15,9 +15,8 @@ class m241102_124933_create_product_1c_prop_type_table extends Migration
     public function safeUp()
     {
         $this->createTable(self::TABLE_NAME, [
-            'id' => $this->string()->notNull()->unique()->comment('Идентификатор из 1С'),
-            'alias' => $this->string()->notNull()->comment('Алиас свойства'),
-            'value' => $this->string()->notNull()->comment('Значение - например, "Срезка"'),
+            'id' => $this->string()->notNull()->unique()->comment('GUID свойства'),
+            'name' => $this->string()->notNull()->comment('Имя свойства')
         ]);
 
         $this->addPrimaryKey('pk_product_1c_prop_type', self::TABLE_NAME, 'id');
diff --git a/erp24/migrations/m241102_124956_create_product_1c_prop_value_table.php b/erp24/migrations/m241102_124956_create_product_1c_prop_value_table.php
deleted file mode 100644 (file)
index ca1ab18..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-
-use yii\db\Migration;
-
-/**
- * Handles the creation of table `{{%product_1c_prop_value}}`.
- */
-class m241102_124956_create_product_1c_prop_value_table extends Migration
-{
-
-    const TABLE_NAME = 'erp24.product_1c_prop_value';
-    /**
-     * {@inheritdoc}
-     */
-    public function safeUp()
-    {
-        $this->createTable(self::TABLE_NAME, [
-            'id' => $this->string()->notNull()->unique()->comment('Идентификатор значения в системе 1С'),
-            'prop_id' => $this->string()->notNull()->comment('Идентификатор свойства для которого присваивается значение'),
-            'value_type' => $this->string()->notNull()->comment('Тип данных значения'),
-            'value_string' => $this->string()->null()->comment('String '),
-            'value_int' => $this->integer()->null()->comment('Integer'),
-            'value_float' => $this->float()->null()->comment('Float'),
-        ]);
-
-        $this->addPrimaryKey('pk_product_1c_prop_value', self::TABLE_NAME, 'id');
-        $this->addForeignKey(
-            'fk_product_1c_prop_value_prop_id',
-            self::TABLE_NAME,
-            'prop_id',
-            '{{%erp24.product_1c_prop_type}}',
-            'id',
-            'CASCADE',
-            'CASCADE'
-        );
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function safeDown()
-    {
-        $this->dropForeignKey('fk_product_1c_prop_value_prop_id', self::TABLE_NAME);
-        $this->dropTable(self::TABLE_NAME);
-
-    }
-}
diff --git a/erp24/migrations/m241102_124956_create_products_1c_additional_characteristics_table.php b/erp24/migrations/m241102_124956_create_products_1c_additional_characteristics_table.php
new file mode 100644 (file)
index 0000000..6fbc2b5
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Handles the creation of table `{{%products_1c_additional_characteristics}}`.
+ */
+class m241102_124956_create_products_1c_additional_characteristics_table extends Migration
+{
+    const TABLE_NAME = 'erp24.products_1c_additional_characteristics';
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $this->createTable(self::TABLE_NAME, [
+            'id' => $this->primaryKey()->comment('Идентификатор инкрементируемый'), // Auto-incrementing primary key
+            'product_id' => $this->string()->notNull()->comment('GUID товара'), // GUID of the product
+            'property_id' => $this->string()->notNull()->comment('ID из product_1c_prop_type'), // Foreign key to property type
+            'value_name' => $this->string()->notNull()->comment('Название свойства, привязанного к продукту и относящегося к данному property_id') // Property name associated with the product
+        ]);
+
+        $this->addForeignKey(
+            'fk_products_1c_additional_characteristics_property_id',
+            self::TABLE_NAME,
+            'property_id',
+            '{{%erp24.product_1c_prop_type}}',
+            'id',
+            'CASCADE',
+            'CASCADE'
+        );
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        $this->dropForeignKey('fk_products_1c_additional_characteristics_property_id', self::TABLE_NAME);
+        $this->dropTable(self::TABLE_NAME);
+    }
+}
\ No newline at end of file
diff --git a/erp24/records/Product1cPropType.php b/erp24/records/Product1cPropType.php
new file mode 100644 (file)
index 0000000..b80f36f
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "product_1c_prop_type".
+ *
+ * @property string $id GUID свойства
+ * @property string $name Имя свойства
+ *
+ * @property Products1cAdditionalCharacteristics[] $products1cAdditionalCharacteristics
+ */
+class Product1cPropType extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'product_1c_prop_type';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['id', 'name'], 'required'],
+            [['id', 'name'], 'string', 'max' => 255],
+            [['id'], 'unique'],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'name' => 'Name',
+        ];
+    }
+
+    /**
+     * Gets query for [[Products1cAdditionalCharacteristics]].
+     *
+     * @return \yii\db\ActiveQuery
+     */
+    public function getProducts1cAdditionalCharacteristics()
+    {
+        return $this->hasMany(Products1cAdditionalCharacteristics::class, ['property_id' => 'id']);
+    }
+}
diff --git a/erp24/records/Products1cAdditionalCharacteristics.php b/erp24/records/Products1cAdditionalCharacteristics.php
new file mode 100644 (file)
index 0000000..eedf9ae
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "products_1c_additional_characteristics".
+ *
+ * @property int $id Идентификатор инкрементируемый
+ * @property string $product_id GUID товара
+ * @property string $property_id ID из product_1c_prop_type
+ * @property string $value_name Название свойства, привязанного к продукту и относящегося к данному property_id
+ *
+ * @property Product1cPropType $property
+ */
+class Products1cAdditionalCharacteristics extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'products_1c_additional_characteristics';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['product_id', 'property_id', 'value_name'], 'required'],
+            [['product_id', 'property_id', 'value_name'], 'string', 'max' => 255],
+            [['property_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product1cPropType::class, 'targetAttribute' => ['property_id' => 'id']],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'product_id' => 'Product ID',
+            'property_id' => 'Property ID',
+            'value_name' => 'Value Name',
+        ];
+    }
+
+    /**
+     * Gets query for [[Property]].
+     *
+     * @return \yii\db\ActiveQuery
+     */
+    public function getProperty()
+    {
+        return $this->hasOne(Product1cPropType::class, ['id' => 'property_id']);
+    }
+}