diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventFight.kt b/CommonCore/SQL/src/de/steamwar/sql/EventFight.kt index bdbce609..285a01f9 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventFight.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/EventFight.kt @@ -237,6 +237,7 @@ class EventFight(id: EntityID) : IntEntity(id), Comparable { override fun delete() = useDb { + EventRelation.deleteRelations(this@EventFight) super.delete() } -} \ No newline at end of file +} diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventGroup.kt b/CommonCore/SQL/src/de/steamwar/sql/EventGroup.kt index 7b20e648..cccbc570 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventGroup.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/EventGroup.kt @@ -159,10 +159,13 @@ class EventGroup(id: EntityID) : IntEntity(id) { } override fun delete() = - useDb { super.delete() } + useDb { + EventRelation.deleteRelations(this@EventGroup) + super.delete() + } enum class EventGroupType { GROUP_STAGE, ELIMINATION_STAGE } -} \ No newline at end of file +} diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventRelation.kt b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.kt index 91ccb9db..41e1bb8c 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventRelation.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.kt @@ -24,8 +24,10 @@ import org.jetbrains.exposed.v1.core.and import org.jetbrains.exposed.v1.core.dao.id.EntityID import org.jetbrains.exposed.v1.core.dao.id.IntIdTable import org.jetbrains.exposed.v1.core.eq +import org.jetbrains.exposed.v1.core.or import org.jetbrains.exposed.v1.dao.IntEntity import org.jetbrains.exposed.v1.dao.IntEntityClass +import org.jetbrains.exposed.v1.jdbc.deleteWhere import org.jetbrains.exposed.v1.jdbc.select object EventRelationTable : IntIdTable("EventRelation") { @@ -59,6 +61,23 @@ class EventRelation(id: EntityID) : IntEntity(id) { fun getGroupRelations(group: EventGroup) = useDb { find { (EventRelationTable.fromId eq group.id.value) and (EventRelationTable.fromType eq FromType.GROUP) }.toList() } + @JvmStatic + fun deleteRelations(fight: EventFight) = + useDb { + EventRelationTable.deleteWhere { + (EventRelationTable.fightId eq fight.id) or + ((EventRelationTable.fromId eq fight.id.value) and (EventRelationTable.fromType eq FromType.FIGHT)) + } + } + + @JvmStatic + fun deleteRelations(group: EventGroup) = + useDb { + EventRelationTable.deleteWhere { + (EventRelationTable.fromId eq group.id.value) and (EventRelationTable.fromType eq FromType.GROUP) + } + } + @JvmStatic fun create(fight: EventFight, fightTeam: FightTeam, fromType: FromType, fromId: Int, fromPlace: Int) = useDb { @@ -159,4 +178,4 @@ class EventRelation(id: EntityID) : IntEntity(id) { enum class FromType { FIGHT, GROUP } -} \ No newline at end of file +}