We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Vapor Toolbox: 2.0.3 Vapor Framework: 2.1.2
Given the following code, Updateable protocol can not convert null to nil for the string as expected:
Updateable
null
nil
final class Reminder: Model { var calendarItemIdentifier: String? struct Properties { static let idKey = "id" static let calendarItemIdentifierKey = "calendar_item_identifier" } init(row: Row) throws { calendarItemIdentifier = try? row.get(Properties.calendarItemIdentifierKey) } func makeRow() throws -> Row { var row = Row() try row.set(Properties.calendarItemIdentifierKey, calendarItemIdentifier) } extension Reminder: Preparation { static func prepare(_ database: Database) throws { try database.create(self) { reminder in reminder.id() reminder.string(Properties.calendarItemIdentifierKey, optional: true) } } static func revert(_ database: Database) throws { try database.delete(self) } } extension Reminder: Updateable { public static var updateableKeys: [UpdateableKey<Reminder>] { return [ UpdateableKey(Properties.calendarItemIdentifierKey, String.self) { object, calendarItemIdentifier in object.calendarItemIdentifier = calendarItemIdentifier } ] } }
Attempting to patch through
func update(req: Request, reminder: Reminder) throws -> ResponseRepresentable { try reminder.update(for: req) try reminder.save() return try reminder }
With
{ "calendar_item_identifier": null }
Fluent is throwing an error
The text was updated successfully, but these errors were encountered:
You need to use String? instead of String if you want to support nil.
String?
String
UpdateableKey(Properties.calendarItemIdentifierKey, String?.self)
Feel free to reopen if this doesn't fix the issue.
Sorry, something went wrong.
No branches or pull requests
Vapor Toolbox: 2.0.3
Vapor Framework: 2.1.2
Given the following code,
Updateable
protocol can not convertnull
tonil
for the string as expected:Attempting to patch through
With
Fluent is throwing an error
The text was updated successfully, but these errors were encountered: