From dfa39a5e868e71a3856365696bbc391acd288d5b Mon Sep 17 00:00:00 2001 From: Logan Wright Date: Sun, 11 Sep 2016 13:41:44 -0400 Subject: [PATCH 1/2] fix update/modify objects --- Sources/Fluent/Query/Query.swift | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Sources/Fluent/Query/Query.swift b/Sources/Fluent/Query/Query.swift index ac206a66..d35a4397 100644 --- a/Sources/Fluent/Query/Query.swift +++ b/Sources/Fluent/Query/Query.swift @@ -45,7 +45,7 @@ public class Query: QueryRepresentable { /** An array of unions, or other entities - that will be queried during this query's + that will be queried during this query's execution. */ public var unions: [Union] @@ -145,8 +145,8 @@ extension QueryRepresentable { /** Attempts the create action for the supplied - serialized data. - + serialized data. + Returns the new entity's identifier. */ public func create(_ serialized: Node?) throws -> Node { @@ -201,7 +201,7 @@ extension QueryRepresentable { let query = try makeQuery() query.action = .delete - + let filter = Filter( T.self, .compare( @@ -228,6 +228,13 @@ extension QueryRepresentable { query.action = .modify query.data = serialized + let idKey = query.database.driver.idKey + serialized?[idKey].flatMap { id in + let entity = T.self + let idFilter = Filter(entity, .compare(idKey, .equals, id)) + query.filters.append(idFilter) + } + try query.run() } } From 58af9f9726e9fd4b57c0f191d4453ba5a80e849a Mon Sep 17 00:00:00 2001 From: Logan Wright Date: Sun, 11 Sep 2016 14:01:35 -0400 Subject: [PATCH 2/2] include fixme warning --- Sources/Fluent/Query/Query.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Fluent/Query/Query.swift b/Sources/Fluent/Query/Query.swift index d35a4397..a08a3daf 100644 --- a/Sources/Fluent/Query/Query.swift +++ b/Sources/Fluent/Query/Query.swift @@ -228,6 +228,7 @@ extension QueryRepresentable { query.action = .modify query.data = serialized + // FIXME: There should be a flag to know if this existed to prevent overwriting existing id let idKey = query.database.driver.idKey serialized?[idKey].flatMap { id in let entity = T.self