ProductToRating.php 1.26 KB
<?php

namespace common\models;

use common\modules\product\models\Product;
use Yii;

/**
 * This is the model class for table "product_to_rating".
 *
 * @property integer $product_to_rating_id
 * @property integer $product_id
 * @property double $value
 *
 * @property Product $product
 */
class ProductToRating extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'product_to_rating';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['product_id'], 'required'],
            [['product_id'], 'integer'],
            [['value'], 'number', 'min' => 0],
            [['product_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => ['product_id' => 'product_id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'product_to_rating_id' => 'Product To Rating ID',
            'product_id' => 'Product ID',
            'value' => 'Value',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getProduct()
    {
        return $this->hasOne(Product::className(), ['product_id' => 'product_id']);
    }
}