A Model using both CompositeID and Children will crash on load.
To Reproduce
final class ParentModel: Model {
static var schema = "parents"
final class Identifier: Fields, Hashable {
@Field(key: "id1")
var id1: String
@Field(key: "id2")
var id2: Int
func hash(into hasher: inout Hasher) {
hasher.combine(id1)
hasher.combine(id2)
}
static func == (lhs: ParentModel.Identifier, rhs: ParentModel.Identifier) -> Bool {
lhs.id1 == rhs.id1 && lhs.id2 == rhs.id2
}
}
@CompositeID
var id: Identifier?
@Children(for: \.$parent)
var children: [ChildModel]
}
final class ChildModel: Model {
static var schema = "children"
@ID(custom: "id")
var id: String?
@Parent(key: "parent")
var parent: ParentModel
}
Use such model layout, and the app will crash on loading ParentModel:
Could not cast value of type 'FluentKit.CompositeIDProperty<Test.ParentModel, Test.ParentModel.Identifier>' (...) to 'FluentKit.IDProperty<Test.ParentModel, Test.ParentModel.Identifier>' (...).
Expected behavior
A child should be able to have a parent with composite ID, which, in the sample layout, specified by parent_id1,parent_id2 with reference to parents(id1,id2). In reverse, a parent with composite ID should also be able to retrieve its children.
Describe the bug
A
Model
using bothCompositeID
andChildren
will crash on load.To Reproduce
Use such model layout, and the app will crash on loading
ParentModel
:Expected behavior
A child should be able to have a parent with composite ID, which, in the sample layout, specified by
parent_id1,parent_id2
with reference toparents(id1,id2)
. In reverse, a parent with composite ID should also be able to retrieve its children.Environment
Additional context
Add any other context about the problem here.