@@ -209,20 +209,23 @@ private object SetHasOneRelationship(object entity,
209
209
210
210
var foreignKey = attr . IdentifiablePropertyName ;
211
211
var entityProperty = entityProperties . FirstOrDefault ( p => p . Name == foreignKey ) ;
212
- if ( entityProperty == null )
212
+ if ( entityProperty == null && rio != null )
213
213
throw new JsonApiException ( 400 , $ "{ contextEntity . EntityType . Name } does not contain a foreign key property '{ foreignKey } ' for has one relationship '{ attr . InternalRelationshipName } '") ;
214
214
215
- // e.g. PATCH /articles
216
- // {... { "relationships":{ "Owner": { "data" :null } } } }
217
- if ( rio == null && Nullable . GetUnderlyingType ( entityProperty . PropertyType ) == null )
218
- throw new JsonApiException ( 400 , $ "Cannot set required relationship identifier '{ attr . IdentifiablePropertyName } ' to null.") ;
215
+ if ( entityProperty != null )
216
+ {
217
+ // e.g. PATCH /articles
218
+ // {... { "relationships":{ "Owner": { "data" :null } } } }
219
+ if ( rio == null && Nullable . GetUnderlyingType ( entityProperty . PropertyType ) == null )
220
+ throw new JsonApiException ( 400 , $ "Cannot set required relationship identifier '{ attr . IdentifiablePropertyName } ' to null.") ;
219
221
220
- var newValue = rio ? . Id ?? null ;
221
- var convertedValue = TypeHelper . ConvertType ( newValue , entityProperty . PropertyType ) ;
222
+ var newValue = rio ? . Id ?? null ;
223
+ var convertedValue = TypeHelper . ConvertType ( newValue , entityProperty . PropertyType ) ;
222
224
223
- _jsonApiContext . RelationshipsToUpdate [ relationshipAttr ] = convertedValue ;
225
+ _jsonApiContext . RelationshipsToUpdate [ relationshipAttr ] = convertedValue ;
224
226
225
- entityProperty . SetValue ( entity , convertedValue ) ;
227
+ entityProperty . SetValue ( entity , convertedValue ) ;
228
+ }
226
229
}
227
230
228
231
return entity ;
0 commit comments