Spine icon indicating copy to clipboard operation
Spine copied to clipboard

Ability to omit relationship null values

Open markst opened this issue 8 years ago • 4 comments

Attributes can be omitted with OmitNullValues serialization options, however if a relationship doesn't exist a null payload will be delivered to relationship URL.

Debug - {"data":null}

markst avatar Aug 24 '16 13:08 markst

Perhaps readonly relationships is adequate for my use case. "jobTitle": ToOneRelationship(JobTitle).readOnly()

markst avatar Aug 24 '16 14:08 markst

I think this is related to this issue. But if I have an optional relationship:

var skills: LinkedResourceCollection?

Spine insists on updating that defined relationship within operation updateRelationships(). Since it's optional I don't wish to update.

Perhaps the filter need to be updated to check for nil?

let relationships = resource.fields.filter { field in
    return field is Relationship && !field.isReadOnly && field.isUpdatable && resource.value(forField: field.name) != nil
}

markst avatar Feb 03 '17 05:02 markst

I suppose it's difficult then to identify whether a relationship is being removed or not?

markst avatar Feb 03 '17 05:02 markst

A LinkedResourceCollection internally keeps that of what resources were added and removed. What is the problem you run into? Spine crashes because the skills variable is nil?

wvteijlingen avatar Feb 07 '17 17:02 wvteijlingen