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