Explorar el Código

modelos y relaciones de eventogrupo

Luis Hernandez hace 3 años
padre
commit
a5cd65937a

+ 6 - 0
migrations/m230130_184544_tabla_grupos_eventos.php

@@ -21,6 +21,9 @@ class m230130_184544_tabla_grupos_eventos extends Migration {
 		$this->alterColumn("Evento", "descripcion", $this->text());
 		$this->dropColumn("Evento", "idGrupo");
 
+		$this->addForeignKey('EventoGrupoIdEventoFK', 'EventoGrupo', 'idEvento', 'Evento', 'id');
+		$this->addForeignKey('EventoGrupoIdGrupoFK', 'EventoGrupo', 'idGrupo', 'Grupo', 'id');
+
 	}
 
 	/**
@@ -28,6 +31,9 @@ class m230130_184544_tabla_grupos_eventos extends Migration {
 	 */	
 	public function safeDown() {
 
+		$this->dropForeignKey("EventoGrupoIdGrupoFK", "EventoGrupo");
+		$this->dropForeignKey("EventoGrupoIdEventoFK", "EventoGrupo");
+		
 		$this->addColumn("Evento", "idGrupo", $this->integer());
 		$this->alterColumn("Evento", "descripcion", $this->string(255));
 		$this->alterColumn("Evento", "nombre", $this->string(100)->notNull());

+ 20 - 0
models/Evento.php

@@ -20,6 +20,8 @@ use Yii;
  * @property string|null $eliminado
  * @property string|null $firebaseId
  *
+ * @property EventoGrupo[] $eventoGrupos
+ * @property Grupo[] $grupos
  * @property Resultado[] $resultados
  */
 class Evento extends \yii\db\ActiveRecord {
@@ -66,6 +68,24 @@ class Evento extends \yii\db\ActiveRecord {
 	}
 
 	/**
+	 * Gets query for [[eventoGrupos]].
+	 *
+	 * @return \yii\db\ActiveQuery
+	 */
+	public function getEventoGrupos() {
+		return $this->hasMany(EventoGrupo::className(), ['idEvento' => 'id']);
+	}
+
+	/**
+	 * Gets query for [[grupos]].
+	 *
+	 * @return \yii\db\ActiveQuery
+	 */
+	public function getGrupos() {
+		return $this->hasMany(Grupo::className(), ['id' => 'idGrupo'])->viaTable('EventoGrupo', ['idEvento' => 'id']);
+	}
+
+	/**
 	 * Gets query for [[resultados]].
 	 *
 	 * @return \yii\db\ActiveQuery

+ 23 - 0
models/EventoGrupo.php

@@ -9,6 +9,9 @@ use Yii;
  *
  * @property int $idEvento
  * @property int $idGrupo
+ *
+ * @property Evento $evento
+ * @property Grupo $grupo
  */
 class EventoGrupo extends \yii\db\ActiveRecord {
 	/**
@@ -27,6 +30,8 @@ class EventoGrupo extends \yii\db\ActiveRecord {
 			[['idEvento', 'idGrupo'], 'default', 'value' => null],
 			[['idEvento', 'idGrupo'], 'integer'],
 			[['idEvento', 'idGrupo'], 'unique', 'targetAttribute' => ['idEvento', 'idGrupo']],
+			[['idEvento'], 'exist', 'skipOnError' => true, 'targetClass' => Evento::className(), 'targetAttribute' => ['idEvento' => 'id']],
+			[['idGrupo'], 'exist', 'skipOnError' => true, 'targetClass' => Grupo::className(), 'targetAttribute' => ['idGrupo' => 'id']],
 		];
 	}
 
@@ -39,4 +44,22 @@ class EventoGrupo extends \yii\db\ActiveRecord {
 			'idGrupo' => 'Id Grupo',
 		];
 	}
+
+	/**
+	 * Gets query for [[evento]].
+	 *
+	 * @return \yii\db\ActiveQuery
+	 */
+	public function getEvento() {
+		return $this->hasOne(Evento::className(), ['id' => 'idEvento']);
+	}
+
+	/**
+	 * Gets query for [[grupo]].
+	 *
+	 * @return \yii\db\ActiveQuery
+	 */
+	public function getGrupo() {
+		return $this->hasOne(Grupo::className(), ['id' => 'idGrupo']);
+	}
 }

+ 20 - 0
models/Grupo.php

@@ -15,6 +15,8 @@ use Yii;
  * @property string|null $eliminado
  * @property string|null $firebaseId
  *
+ * @property EventoGrupo[] $eventoGrupos
+ * @property Evento[] $eventos
  * @property Usuario[] $usuarios
  * @property UsuarioGrupo[] $usuariosGrupos
  */
@@ -55,6 +57,24 @@ class Grupo extends \yii\db\ActiveRecord {
 	}
 
 	/**
+	 * Gets query for [[eventoGrupos]].
+	 *
+	 * @return \yii\db\ActiveQuery
+	 */
+	public function getEventoGrupos() {
+		return $this->hasMany(EventoGrupo::className(), ['idGrupo' => 'id']);
+	}
+
+	/**
+	 * Gets query for [[eventos]].
+	 *
+	 * @return \yii\db\ActiveQuery
+	 */
+	public function getEventos() {
+		return $this->hasMany(Evento::className(), ['id' => 'idEvento'])->viaTable('EventoGrupo', ['idGrupo' => 'id']);
+	}
+
+	/**
 	 * Gets query for [[usuarios]].
 	 *
 	 * @return \yii\db\ActiveQuery

+ 9 - 0
modules/v1/models/Evento.php

@@ -25,10 +25,19 @@ class Evento extends ModeloEvento {
 
   public function extraFields() {
     return [
+			'eventoGrupos',
+			'grupos',
       'resultados',
     ];
   }
 
+	public function getEventoGrupos() {
+		return $this->hasMany(EventoGrupo::className(), ['idEvento' => 'id']);
+	}
+
+	public function getGrupos() {
+		return $this->hasMany(Grupo::className(), ['id' => 'idGrupo'])->viaTable('EventoGrupo', ['idEvento' => 'id']);
+	}
 
 	public function getResultados() {
 		return $this->hasMany(Resultado::className(), ['idEvento' => 'id']);

+ 16 - 0
modules/v1/models/EventoGrupo.php

@@ -13,4 +13,20 @@ class EventoGrupo extends ModeloEventoGrupo {
     ];
   }
 
+  public function extraFields() {
+    return [
+      'evento',
+      'grupo'
+    ];
+  }
+
+  public function getEvento() {
+		return $this->hasOne(Evento::className(), ['id' => 'idEvento']);
+	}
+
+
+	public function getGrupo() {
+		return $this->hasOne(Grupo::className(), ['id' => 'idGrupo']);
+	}
+
 }

+ 10 - 0
modules/v1/models/Grupo.php

@@ -20,11 +20,21 @@ class Grupo extends ModeloGrupo {
 
   public function extraFields() {
     return [
+      'eventoGrupos',
+      'eventos',
       'usuarios',
       'usuariosGrupos',
     ];
   }
 
+  public function getEventoGrupos() {
+		return $this->hasMany(EventoGrupo::className(), ['idGrupo' => 'id']);
+	}
+
+	public function getEventos() {
+		return $this->hasMany(Evento::className(), ['id' => 'idEvento'])->viaTable('EventoGrupo', ['idGrupo' => 'id']);
+	}
+
   public function getUsuarios() {
 		return $this->hasMany(Usuario::className(), ['id' => 'idUsuario'])->viaTable('UsuarioGrupo', ['idGrupo' => 'id']);
 	}