Compare commits

...

1 Commits

Author SHA1 Message Date
Luke S 99d9d96dbb Permit missing data key for optional relationships
This prevents a decoding error when `included[].relationships.*.data` is missing, using the same logic as if it was nil.
2019-12-02 18:42:03 -05:00
+1 -1
View File
@@ -170,7 +170,7 @@ extension ToOneRelationship: Codable where Identifiable.Identifier: OptionalId {
// succeeds and then attempt to coerce nil to a Identifier
// type at which point we can store nil in `id`.
let anyNil: Any? = nil
if try container.decodeNil(forKey: .data) {
if try !container.contains(.data) || container.decodeNil(forKey: .data) {
guard let val = anyNil as? Identifiable.Identifier else {
throw DecodingError.valueNotFound(
Self.self,