Skip to content

Commit

Permalink
Merge pull request #88 from vapor/update-patch
Browse files Browse the repository at this point in the history
fix update/modify objects
  • Loading branch information
loganwright authored Sep 11, 2016
2 parents 345b4ea + 58af9f9 commit 45902e1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Sources/Fluent/Query/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class Query<T: Entity>: 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]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -201,7 +201,7 @@ extension QueryRepresentable {
let query = try makeQuery()

query.action = .delete

let filter = Filter(
T.self,
.compare(
Expand All @@ -228,6 +228,14 @@ 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
let idFilter = Filter(entity, .compare(idKey, .equals, id))
query.filters.append(idFilter)
}

try query.run()
}
}
Expand Down

0 comments on commit 45902e1

Please sign in to comment.