You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello guys! After about a day of having a strange belongsTo error I got it to work! I found out that when fetching an associtation you can't name a foreign key and .forKey() (the associationKey == the name of the variable in the combined struct) the same... or that is my explanation for the error. Maybe add this in every belongsTo documentation 😆
Works:
publicstructSession:FetchableRecord,Decodable,Equatable{publicvarsession:SessionRecordpublicvarbar:SessionBarRecordpublicinit(
session:SessionRecord,
barID:SessionBarRecord){self.session = session
self.bar = barID
}enumCodingKeys:String,CodingKey{case session
case bar
}staticfunc request(sessionID:SessionRecord.ID)->QueryInterfaceRequest<Session>{returnSessionRecord.including(required:SessionRecord.bar.forKey("bar")).asRequest(of:Session.self)}}
publicstructSessionRecord:Identifiable,Codable,Equatable,FetchableRecord,TableRecord,PersistableRecord{publicstaticvardatabaseTableName:String{"Session"}staticletbar=belongsTo(SessionBarRecord.self)publicletid:StringpublicletbarID:SessionBarRecord.IDenumCodingKeys:String,CodingKey{case id
case barID
}publicinit(
id:ID,
barID:SessionBarRecord.ID){self.id = id
self.barID = barID
}}publicstructSessionBarRecord:Identifiable,Codable,Equatable,FetchableRecord,TableRecord,PersistableRecord{publicstaticvardatabaseTableName:String{"SessionBar"}publicvarid:StringpublicletchosenLink:String?enumCodingKeys:String,CodingKey{case id
case chosenLink
}publicinit(
id:ID,
chosenLink:String?){self.id = id
self.chosenLink = chosenLink
}}
The error I had:
error: Swift.DecodingError.dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around line 1, column 0." UserInfo={NSDebugDescription=Invalid value around line 1, column 0., NSJSONSerializationErrorIndex=0})))
SessionBarRecords' decoder got called with a single value (the ID of the SessionBarRecord) instead of with a container of all its contents.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello guys! After about a day of having a strange belongsTo error I got it to work! I found out that when fetching an associtation you can't name a foreign key and
.forKey()
(the associationKey == the name of the variable in the combined struct) the same... or that is my explanation for the error. Maybe add this in every belongsTo documentation 😆Works:
Crashes:
Records:
The error I had:
SessionBarRecords' decoder got called with a single value (the ID of the SessionBarRecord) instead of with a container of all its contents.
Beta Was this translation helpful? Give feedback.
All reactions