<?php

namespace common\modules\triggers\models;

use Yii;

/**
 * This is the model class for table "trigger_connection".
 *
 * @property integer $id
 * @property integer $scenario_id
 * @property integer $trigger_id
 *
 * @property TriggerTrigger $trigger
 * @property TriggerScenario $scenario
 */
class TriggerConnection extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'trigger_connection';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['scenario_id', 'trigger_id'], 'required'],
            [['scenario_id', 'trigger_id'], 'integer'],
            [['trigger_id'], 'exist', 'skipOnError' => true, 'targetClass' => TriggerTrigger::className(), 'targetAttribute' => ['trigger_id' => 'id']],
            [['scenario_id'], 'exist', 'skipOnError' => true, 'targetClass' => TriggerScenario::className(), 'targetAttribute' => ['scenario_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'scenario_id' => 'Scenario ID',
            'trigger_id' => 'Trigger ID',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTrigger()
    {
        return $this->hasOne(TriggerTrigger::className(), ['id' => 'trigger_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getScenario()
    {
        return $this->hasOne(TriggerScenario::className(), ['id' => 'scenario_id']);
    }
}
