From eb63485dfd6fbd0773a25e1b94830fbcedaa8266 Mon Sep 17 00:00:00 2001 From: tanner0101 Date: Wed, 28 Mar 2018 14:02:40 -0400 Subject: [PATCH] temporary reflect property fix --- Sources/Fluent/Migration/Migration.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Sources/Fluent/Migration/Migration.swift b/Sources/Fluent/Migration/Migration.swift index 417385c8..d9328c8f 100644 --- a/Sources/Fluent/Migration/Migration.swift +++ b/Sources/Fluent/Migration/Migration.swift @@ -24,9 +24,7 @@ public protocol Migration { extension Model where Database: SchemaSupporting { /// Automatically adds `SchemaField`s for each of this `Model`s properties. public static func addProperties(to builder: SchemaCreator) throws { - guard let idProperty = try Self.reflectProperty(forKey: idKey) else { - throw FluentError(identifier: "reflectProperty", reason: "No property reflected for \(idKey)", source: .capture()) - } + let idProperty = try Self.reflectProperty(forKey: idKey) let properties = try Self.reflectProperties() for property in properties { @@ -34,6 +32,13 @@ extension Model where Database: SchemaSupporting { continue } + let isID: Bool + if let id = idProperty { + isID = property.path == id.path + } else { + isID = (property.path == ["id"] || property.path == ["_id"]) + } + let type: Any.Type let isOptional: Bool if let o = property.type as? AnyOptionalType.Type { @@ -48,7 +53,7 @@ extension Model where Database: SchemaSupporting { name: property.path.first ?? "", type: Database.fieldType(for: type), isOptional: isOptional, - isIdentifier: property.path == idProperty.path + isIdentifier: isID ) builder.schema.addFields.append(field) }