Create Fluent Model with String Enum

964 Views Asked by At

Here is my Fluent Model

struct Ailment: PostgreSQLModel {

enum Frequency: String , Content {
    case regular = "Regular"
    case occasional = "Occasional"
    case incidentFound = "Incident Found"
}

var id: Int?

var ailment: String

var frequency: Frequency

var dateIdentified: Date?

var underMedication: Bool

var breifDescription: String

}

I am able to create Fluent Model with Int Enum, but it does not work with String Enum,

I am getting below Exception

Fatal error: Error raised at top level: ⚠️ DecodingError: Cannot initialize Frequency from invalid String value 1

Thanks in advance :)

1

There are 1 best solutions below

5
On

Referring this Issue it works with Vapor 3.0.6 and Fluent 3.0.0. The table should be created correct if your enum is conform to ReflectionDecodable.