ProductVideo.php 1.93 KB
<?php
    
    namespace artweb\artbox\ecommerce\models;
    
    use yii\db\ActiveRecord;
    
    /**
     * This is the model class for table "product_video".
     *
     * @property integer $id
     * @property integer $product_id
     * @property string  $url
     * @property Product $product
     * @property string  $title
     */
    class ProductVideo extends ActiveRecord
    {
        /**
         * @inheritdoc
         */
        public static function tableName()
        {
            return 'product_video';
        }
        
        /**
         * @inheritdoc
         */
        public function rules()
        {
            return [
                [
                    [ 'product_id' ],
                    'integer',
                ],
                [
                    [
                        'url',
                        'title',
                    ],
                    'string',
                    'max' => 255,
                ],
                [
                    ['url'],
                    'required',
                ],
                [
                    [ 'product_id' ],
                    'exist',
                    'skipOnError'     => true,
                    'targetClass'     => Product::className(),
                    'targetAttribute' => [ 'product_id' => 'id' ],
                ],
            ];
        }
        
        /**
         * @inheritdoc
         */
        public function attributeLabels()
        {
            return [
                'id'         => \Yii::t('app', 'ID'),
                'product_id' => \Yii::t('app', 'Product ID'),
                'url'        => \Yii::t('app', 'Url'),
                'title'      => \Yii::t('app', 'Title'),
            ];
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getProduct()
        {
            return $this->hasOne(Product::className(), [ 'id' => 'product_id' ]);
        }
    }