Skip to content

Commit 912f45c

Browse files
committed
fix(HasOneAttribute): return null if property doesnt exist
1 parent 3c98b70 commit 912f45c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/JsonApiDotNetCore/Models/HasOneAttribute.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,20 @@ public override void SetValue(object entity, object newValue)
5454

5555
// HACK: this will likely require boxing
5656
// we should be able to move some of the reflection into the ContextGraphBuilder
57+
/// <summary>
58+
/// Gets the value of the independent identifier (e.g. Article.AuthorId)
59+
/// </summary>
60+
///
61+
/// <param name="entity">
62+
/// An instance of dependent resource
63+
/// </param>
64+
///
65+
/// <returns>
66+
/// The property value or null if the property does not exist on the model.
67+
/// </returns>
5768
internal object GetIdentifiablePropertyValue(object entity) => entity
5869
.GetType()
5970
.GetProperty(IdentifiablePropertyName)
60-
.GetValue(entity);
71+
?.GetValue(entity);
6172
}
6273
}

0 commit comments

Comments
 (0)