浏览代码

Agregado el id usuario en incidentes

Jogibeda 7 月之前
父节点
当前提交
dd66c8cd52
共有 2 个文件被更改,包括 53 次插入1 次删除
  1. 44 0
      migrations/m240927_170414_Agregar_idUsuario_en_incidentes.php
  2. 9 1
      models/Incidente.php

+ 44 - 0
migrations/m240927_170414_Agregar_idUsuario_en_incidentes.php

@@ -0,0 +1,44 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m240927_170414_Agregar_idUsuario_en_incidentes
+ */
+class m240927_170414_Agregar_idUsuario_en_incidentes extends Migration
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $this->addColumn('Incidente', 'idUsuario', $this->string(36));
+        $this->addForeignKey('IncidenteUsuarioFK', 'Incidente', 'idUsuario', 'Usuario', 'id');
+
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        $this->dropForeignKey('IncidenteUsuarioFK', 'Incidente');
+        $this->dropColumn('Incidente', 'idUsuario');
+
+    }
+
+    /*
+    // Use up()/down() to run migration code without a transaction.
+    public function up()
+    {
+
+    }
+
+    public function down()
+    {
+        echo "m240927_170414_Agregar_idUsuario_en_incidentes cannot be reverted.\n";
+
+        return false;
+    }
+    */
+}

+ 9 - 1
models/Incidente.php

@@ -11,12 +11,14 @@ use Yii;
  * @property string $nombre
  * @property string|null $fechaIncidente
  * @property string|null $idObra
+ * @property string|null $idUsuario
  * @property string|null $descripcion
  * @property string|null $creado
  * @property string|null $modificado
  * @property string|null $eliminado
  *
  * @property IncidenteEmpleado[] $incidenteEmpleado
+ * @property Empleado $idEmpleado
  */
 class Incidente extends ModeloBase
 {
@@ -36,10 +38,11 @@ class Incidente extends ModeloBase
         return [
             [['id', 'nombre', 'idObra'], 'required'],
             [['fechaIncidente','creado', 'modificado', 'eliminado'], 'safe'],
-            [['id', 'idObra'], 'string', 'max' => 36],
+            [['id', 'idObra','idUsuario'], 'string', 'max' => 36],
             [['nombre', 'descripcion'], 'string', 'max' => 100],
             [['id'], 'unique'],
             [['idObra'], 'exist', 'skipOnError' => true, 'targetClass' => Obra::class, 'targetAttribute' => ['idObra' => 'id']],
+            [['idUsuario'], 'exist', 'skipOnError' => true, 'targetClass' => Usuario::class, 'targetAttribute' => ['idUsuario' => 'id']],
 
         ];
     }
@@ -54,6 +57,7 @@ class Incidente extends ModeloBase
             'nombre' => 'Nombre',
             'fechaIncidente' => 'Fecha Incidente',
             'idObra' => 'ID Obra',
+            'idUsuario' => 'Id Usuario',
             'descripcion' => 'Descripcion',
             'creado' => 'Creado',
             'modificado' => 'Modificado',
@@ -72,4 +76,8 @@ class Incidente extends ModeloBase
     {
         return $this->hasOne(Obra::class, ['id' => 'idObra']);
     }
+    public function getUsuario()
+    {
+        return $this->hasOne(Usuario::class, ['id' => 'idUsuario']);
+    }
 }