Skip to content

Meow: Support more types in makePartialUpdate #342

@sliemeobn

Description

@sliemeobn

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions