Currently the ModelUpdater type is very limited, only allowing access to properties that are a Primitive.
This excludes a wide variety of property types, such as Optionals, RawRepresentables, References, or arrays of these types.
public subscript<P: Primitive>(dynamicMember keyPath: WritableKeyPath<M, QueryableField<P>>) -> P {
get {
self.update.model[keyPath: keyPath].value!
}
set {
self.update.model[keyPath: keyPath].value = newValue
let path = M.resolveFieldPath(keyPath)
self.update.changes[path] = newValue
}
}
A solution could be to constrain this access to PrimitiveEncodable & Codable instead of Primitive. However, the encodePrimitive() function is potentially throwing, which is not ideal in the set accessor.
Alternatively, we could add a lot of typed overloads similar to the ModelUpdateQuery.setField functions.
Currently the
ModelUpdater
type is very limited, only allowing access to properties that are aPrimitive
.This excludes a wide variety of property types, such as Optionals, RawRepresentables, References, or arrays of these types.
A solution could be to constrain this access to
PrimitiveEncodable & Codable
instead ofPrimitive
. However, theencodePrimitive()
function is potentially throwing, which is not ideal in theset
accessor.Alternatively, we could add a lot of typed overloads similar to the
ModelUpdateQuery.setField
functions.