<?php

namespace common\models;

use Yii;
use yii\db\ActiveRecord;

/**
 * This is the model class for table "item_scale".
 *
 * @property integer $id
 * @property string $name
 * @property integer $scale
 * @property integer $pid
 */
class ItemScale extends ActiveRecord
{
    public function scenarios()
    {
        return [
            'insert'=>['name','scale','pid']
        ];
    }

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'item_scale';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['scale', 'pid'], 'integer'],
            [['pid'], 'required'],
            [['name'], 'string', 'max' => 25],
            [['name','scale','pid'],'required','on'=>'insert']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '更换项目(配件名)',
            'scale' => '比例',
            'pid' => '父级分类',
        ];
    }

    /**
     *------------------------------------------------------------
     *  获取指定pid下的所有子类
     * @param int $id
     * @return  object
     * @author liuyingjie
     *------------------------------------------------------------
     */
    public function getCategory($id=0){
        return self::find()->where('pid='.$id)->all();
    }
    public function getMiddleScaleHour(){
        return $this->hasMany(MiddleScaleHour::className(),['scale_id'=>'id']);
    }
}
