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');
+++ /dev/null
-<?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);
-
- }
-}
--- /dev/null
+<?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
--- /dev/null
+<?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']);
+ }
+}
--- /dev/null
+<?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']);
+ }
+}