OdooToProduct.php 2.42 KB
<?php
    
    namespace artbox\odoo\models;
    
    use artbox\catalog\models\Product;
    use Yii;
    use yii\db\ActiveRecord;
    
    /**
     * This is the model class for table "odoo_to_product".
     *
     * @property integer $product_id
     * @property integer $remote_id
     * @property Product $product
     */
    class OdooToProduct extends ActiveRecord
    {
        /**
         * @inheritdoc
         */
        public static function primaryKey()
        {
            return [
                'product_id',
                'remote_id',
            ];
        }
        
        /**
         * @inheritdoc
         */
        public static function tableName()
        {
            return 'odoo_to_product';
        }
        
        /**
         * @inheritdoc
         */
        public function rules()
        {
            return [
                [
                    [
                        'product_id',
                        'remote_id',
                    ],
                    'required',
                ],
                [
                    [
                        'product_id',
                        'remote_id',
                    ],
                    'integer',
                ],
                [
                    [
                        'product_id',
                        'remote_id',
                    ],
                    'unique',
                    'targetAttribute' => [
                        'product_id',
                        'remote_id',
                    ],
                    'message'         => 'The combination of Product ID and Remote ID has already been taken.',
                ],
                [
                    [ 'product_id' ],
                    'exist',
                    'skipOnError'     => true,
                    'targetClass'     => Product::className(),
                    'targetAttribute' => [ 'product_id' => 'id' ],
                ],
            ];
        }
        
        /**
         * @inheritdoc
         */
        public function attributeLabels()
        {
            return [
                'product_id' => Yii::t('odoo', 'Product ID'),
                'remote_id'  => Yii::t('odoo', 'Remote ID'),
            ];
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getProduct()
        {
            return $this->hasOne(Product::className(), [ 'id' => 'product_id' ]);
        }
    }