Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit c540507

Browse files
committed
Use create instead of save
This allows specifying an id
1 parent 2090c3e commit c540507

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Sources/Sugar/Helpers/Model.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,22 @@ public extension Model {
1111
.unwrap(or: Abort(.notFound, reason: "\(Self.self) with id \(id) not found"))
1212
}
1313

14-
func saveOrUpdate (
14+
@available(*, deprecated, message: "use `creatOrUpdate(given:withSoftDeleted:restore:on)`")
15+
func saveOrUpdate(
16+
given filters: [FilterOperator<Self.Database, Self>],
17+
withSoftDeleted: Bool = false,
18+
restore: Bool = false,
19+
on db: DatabaseConnectable
20+
) throws -> Future<Self> {
21+
return try createOrUpdate(
22+
given: filters,
23+
withSoftDeleted: withSoftDeleted,
24+
restore: restore,
25+
on: db
26+
)
27+
}
28+
29+
func createOrUpdate(
1530
given filters: [FilterOperator<Self.Database, Self>],
1631
withSoftDeleted: Bool = false,
1732
restore: Bool = false,
@@ -25,7 +40,7 @@ public extension Model {
2540

2641
return query.first().flatMap(to: Self.self) { result in
2742
guard let result = result else {
28-
return self.save(on: db)
43+
return self.create(on: db)
2944
}
3045

3146
var copy = self

0 commit comments

Comments
 (0)