ProductToProductOptionExcl.php 2.63 KB
<?php
    
    namespace artbox\catalog\models;
    
    use Yii;
    use yii\db\ActiveRecord;

    /**
     * This is the model class for table "product_to_product_option_excl".
     *
     * @property integer           $product_id
     * @property integer           $product_option_excl_id
     *
     * @property Product           $product
     * @property ProductOptionExcl $productOptionExcl
     */
    class ProductToProductOptionExcl extends ActiveRecord
    {
        /**
         * @inheritdoc
         */
        public static function tableName()
        {
            return 'product_to_product_option_excl';
        }
        
        /**
         * @inheritdoc
         */
        public function rules()
        {
            return [
                [
                    [
                        'product_id',
                        'product_option_excl_id',
                    ],
                    'required',
                ],
                [
                    [
                        'product_id',
                        'product_option_excl_id',
                    ],
                    'integer',
                ],
                [
                    [ 'product_id' ],
                    'exist',
                    'skipOnError'     => true,
                    'targetClass'     => Product::className(),
                    'targetAttribute' => [ 'product_id' => 'id' ],
                ],
                [
                    [ 'product_option_excl_id' ],
                    'exist',
                    'skipOnError'     => true,
                    'targetClass'     => ProductOptionExcl::className(),
                    'targetAttribute' => [ 'product_option_excl_id' => 'id' ],
                ],
            ];
        }
        
        /**
         * @inheritdoc
         */
        public function attributeLabels()
        {
            return [
                'product_id'             => Yii::t('catalog', 'Product ID'),
                'product_option_excl_id' => Yii::t('catalog', 'Product Option Excl ID'),
            ];
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getProduct()
        {
            return $this->hasOne(Product::className(), [ 'id' => 'product_id' ])
                        ->inverseOf('productToProductOptionExcls');
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getProductOptionExcls()
        {
            return $this->hasOne(ProductOptionExcl::className(), [ 'id' => 'product_option_excl_id' ])
                        ->inverseOf('productToProductOptionExcls');
        }
    }