diff --git a/app/src/main/kotlin/database/exposed/EnumSetColumn.kt b/app/src/main/kotlin/database/exposed/EnumSetColumn.kt index 722e45c..ad54937 100644 --- a/app/src/main/kotlin/database/exposed/EnumSetColumn.kt +++ b/app/src/main/kotlin/database/exposed/EnumSetColumn.kt @@ -38,16 +38,16 @@ public inline fun > Table.enumerationSet(name: String): Colu public class EnumSetColumnType>(private val klass: KClass) : ColumnType() { // Keep the enum constants for when decoding from the DB - private val enumConstants by lazy { klass.java.enumConstants } + private val enumConstants by lazy { klass.java.enumConstants.associateBy { it.name.uppercase() } } /** The Postgres integer array type. Eg: INTEGER[] */ - override fun sqlType(): String = "${currentDialect.dataTypeProvider.integerType()}[]" + override fun sqlType(): String = "${currentDialect.dataTypeProvider.textType()}[]" /** When writing the value, it can either be a full on list, or individual values. */ override fun notNullValueToDB(value: Any): Any = when (value) { - is Collection<*> -> value.filterIsInstance>().map { it.ordinal } + is Collection<*> -> value.filterIsInstance>().map(Enum<*>::name) is Int -> value - is Enum<*> -> value.ordinal + is Enum<*> -> value.name else -> error("$value of ${value::class.qualifiedName} is not valid for enum set ${klass.simpleName}") } @@ -72,6 +72,6 @@ public class EnumSetColumnType>(private val klass: KClass) : Colu } } - private fun Array<*>.toEnumSet() = filterIsInstance().map { enumConstants[it] }.toSet() - private fun Collection<*>.toEnumSet() = filterIsInstance().map { enumConstants[it] }.toSet() + private fun Array<*>.toEnumSet() = filterIsInstance().map { enumConstants[it.uppercase()] }.toSet() + private fun Collection<*>.toEnumSet() = filterIsInstance().map { enumConstants[it.uppercase()] }.toSet() }