Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using enums as dictionary keys #205

Open
CoolONEOfficial opened this issue Mar 24, 2021 · 0 comments
Open

Using enums as dictionary keys #205

CoolONEOfficial opened this issue Mar 24, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@CoolONEOfficial
Copy link

CoolONEOfficial commented Mar 24, 2021

Describe the bug

I can't use enums as dictionary keys.

To Reproduce

Example:

enum MyEnum: String, Codable {
    case one
}

final class MyModel: Model {
    static var schema: String  = "tests"

    @ID(key: .id)
    var id: UUID?

    @Field(key: "test")
    var test: [MyEnum : Float]
}

struct CreateMigration: Migration {
    func prepare(on database: Database) -> EventLoopFuture<Void> {
        return database.schema(MyModel.schema)
            .id()
            .field("test", .dictionary(of: .float), .required)
            .create()
    }

    func revert(on database: Database) -> EventLoopFuture<Void> {
        return database.schema(MyModel.schema).delete()
    }
}

let test = MyModel()
test.test = [.one: Float(1)]
test.save(on: app.db)

Steps to reproduce the behavior:

  1. Execute migration
  2. Execute MyModel creation
  3. See error "Array does not contain all: TEXT" at PostgresDataEncoder

Expected behavior

Create database schema correctly

Environment

  • Vapor Framework version: 4.35.0
  • Vapor Toolbox version: 18.3.0
  • OS version: macOS Big Sur 11.2.1 (20D74)
@CoolONEOfficial CoolONEOfficial added the bug Something isn't working label Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant