-
-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or request
Description
Vapor 4 cannot decode dates.
Steps to reproduce
-
Create an empty project using vapor-beta toolbox and using a SQLite database for testing purposes.
-
Open Todo.swift file and add a field to store a date
Todo model file looks:
import Fluent
import Vapor
final class Todo: Model, Content {
static let schema = "todos"
@ID(key: .id)
var id: UUID?
@Field(key: "title")
var title: String
@Field(key: "date")
var date: Date
init() { }
init(id: UUID? = nil, title: String, date: Date) {
self.id = id
self.title = title
self.date = date
}
}- Configure the field on the migration file.
import Fluent
struct CreateTodo: Migration {
func prepare(on database: Database) -> EventLoopFuture<Void> {
return database.schema("todos")
.id()
.field("title", .string, .required)
.field("date", .date, .required)
.create()
}
func revert(on database: Database) -> EventLoopFuture<Void> {
return database.schema("todos").delete()
}
}-
Run the migrations.
-
Create a new Todo with ISO8601 date.
-
Try to get the todos. It fails.
Expected behavior
The list of todos is returned.
Actual behavior
[ ERROR ] invalid field: date type: Date error: Decoding error: Value of type 'Date' required for key ''.
Environment
- Vapor Framework version: 4.0.0-rc.3.12
- Fluent Framework version: 4.0.0-rc.1
- Fluent-kit Framework version: 4.0.0-rc.1.16
- Fluent-sqlite-driver Framework version: 4.0.0-rc.1.1
- OS version: macOS 10.15.4
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or request