<?php

namespace common\models;

use common\behaviors\CommentBehavior;
use common\modules\user\models\User;
use Yii;
use yii\behaviors\BlameableBehavior;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "{{%search_record}}".
 *
 * @property integer $id
 * @property string $keyword
 * @property integer $created_at
 * @property integer $updated_at
 * @property integer $user_id
 * @property integer $count
 * @property integer $del
 */
class SearchRecord extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%search_record}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['keyword'], 'required'],
            [['user_id','count','del'], 'integer'],
            [['keyword'], 'string', 'max' => 128],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'keyword' => '关键词',
            'created_at' => 'created_at',
            'updated_at' => 'updated_at',
            'user_id' => '用户',
            'count' => '次数',
            'del' => '是否已删除',
        ];
    }

    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
            ],
            [
                'class' => BlameableBehavior::className(),
                'createdByAttribute' => 'user_id',
                'updatedByAttribute' => false,
            ],
        ];
    }

    public function getUser()
    {
        return $this->hasOne(User::className(), ['id' => 'user_id']);
    }
}
