Closed kwakueshun closed 3 years ago
Update: Doing this worked.
alias = Mapper<RepoAlias>().map(JSON: map.JSON)
But I wonder if this has performance issues having to create Mapper<RepoAlias>()
everytime and if there is a better way to do this.
Update: Was able to do this without creating the Mapper
func mapRelationShip<T: Mappable>(
fromTopLevel map: Map,
toAttributeWithKeyPath keyPath: ReferenceWritableKeyPath<Self, T?>
) {
if let object = T.init(map: map) {
self[keyPath: keyPath] = object
self[keyPath: keyPath]?.mapping(map: map)
}
}
Your JSON dictionary:
Your model:
What you did:
What you expected:
I expected to have a way to do this but did not find documentation on this. Context, this would be easier to do if it was a nested object in the top json but it is not in this case but rather taking keys from the top level object to create another mappable object.