diff --git a/Sources/Fluent/Relations/Children.swift b/Sources/Fluent/Relations/Children.swift index bb108dad..309f9ef8 100644 --- a/Sources/Fluent/Relations/Children.swift +++ b/Sources/Fluent/Relations/Children.swift @@ -14,7 +14,7 @@ extension Children: QueryRepresentable { throw RelationError.noIdentifier } - let foreignId = foreignKey ?? "\(type(of: parent))_\(T.idKey)".lowercased() + let foreignId = foreignKey ?? "\(type(of: parent).name)_\(T.idKey)".lowercased() return try T.query().filter(foreignId, ident) } } diff --git a/Tests/FluentTests/ChildTests.swift b/Tests/FluentTests/ChildTests.swift index d3b74d4a..b36cd844 100644 --- a/Tests/FluentTests/ChildTests.swift +++ b/Tests/FluentTests/ChildTests.swift @@ -47,13 +47,13 @@ class Owner: Entity { } static func prepare(_ database: Fluent.Database) throws { - try database.create("Owners") { pet in + try database.create(entity) { pet in pet.id() pet.string("name") } } static func revert(_ database: Fluent.Database) throws { - try database.delete("Pets") + try database.delete(Owner.entity) } func makeNode(context: Context) throws -> Node { @@ -86,14 +86,14 @@ class Pet: Entity { } static func prepare(_ database: Fluent.Database) throws { - try database.create("Pets") { pet in + try database.create(entity) { pet in pet.id() pet.string("name") pet.parent(Owner.self, optional: false) } } static func revert(_ database: Fluent.Database) throws { - try database.delete("Pets") + try database.delete(Pet.entity) } func makeNode(context: Context) throws -> Node {