wvteijlingen / Spine

A Swift library for working with JSON:API APIs. It supports mapping to custom model classes, fetching, advanced querying, linking and persisting.
MIT License
266 stars 109 forks source link

Ability to omit relationship null values #99

Open markst opened 8 years ago

markst commented 8 years ago

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 commented 8 years ago

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

markst commented 7 years ago

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 commented 7 years ago

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

wvteijlingen commented 7 years ago

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?