Skip to content

Commit

Permalink
Because Mongo is terrible, don't use the new defaulting behavior when…
Browse files Browse the repository at this point in the history
… the database isn't SQL.
  • Loading branch information
gwynne committed Feb 17, 2024
1 parent 73c1966 commit 1c1508f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Sources/FluentKit/Model/Model+CRUD.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import NIOCore
import protocol SQLKit.SQLDatabase

extension Model {
public func save(on database: Database) -> EventLoopFuture<Void> {
Expand All @@ -22,7 +23,7 @@ extension Model {
self.anyID.generate()
let promise = database.eventLoop.makePromise(of: DatabaseOutput.self)
Self.query(on: database)
.set(self.collectInput(withDefaultedValues: true))
.set(self.collectInput(withDefaultedValues: database is SQLDatabase))
.action(.create)
.run { promise.succeed($0) }
.cascadeFailure(to: promise)
Expand All @@ -36,7 +37,7 @@ extension Model {
}
} else {
return Self.query(on: database)
.set(self.collectInput(withDefaultedValues: true))
.set(self.collectInput(withDefaultedValues: database is SQLDatabase))
.action(.create)
.run()
.flatMapThrowing {
Expand Down Expand Up @@ -179,7 +180,7 @@ extension Collection where Element: FluentKit.Model {
}.create(model, on: database)
}, on: database.eventLoop).flatMap {
Element.query(on: database)
.set(self.map { $0.collectInput(withDefaultedValues: true) })
.set(self.map { $0.collectInput(withDefaultedValues: database is SQLDatabase) })
.create()
}.map {
for model in self {
Expand Down

0 comments on commit 1c1508f

Please sign in to comment.