Skip to content

Commit

Permalink
temporary reflect property fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed Mar 28, 2018
1 parent 55c0a96 commit eb63485
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Sources/Fluent/Migration/Migration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,21 @@ 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<Self>) 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 {
guard property.path.count == 1 else {
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 {
Expand All @@ -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)
}
Expand Down

0 comments on commit eb63485

Please sign in to comment.