Skip to content

Exception thrown if relationship name doesn't match navigation property name #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jaredcnance opened this issue Jul 25, 2018 · 0 comments · Fixed by #355
Closed

Exception thrown if relationship name doesn't match navigation property name #354

jaredcnance opened this issue Jul 25, 2018 · 0 comments · Fixed by #355
Labels

Comments

@jaredcnance
Copy link
Contributor

jaredcnance commented Jul 25, 2018

Discovered in v2.4.0-beta3

JsonApiException: N2JsonApi.Models.Item does not contain a relationship named ...
JsonApiDotNetCore.Internal.ContextGraph in GetRelationship

public object GetRelationship<TParent>(TParent entity, string relationshipName)
{
var parentEntityType = entity.GetType();
var navigationProperty = parentEntityType
.GetProperties()
.SingleOrDefault(p => string.Equals(p.Name, relationshipName, StringComparison.OrdinalIgnoreCase));
if (navigationProperty == null)
throw new JsonApiException(400, $"{parentEntityType} does not contain a relationship named {relationshipName}");
return navigationProperty.GetValue(entity);
}

Update

Caused by: https://github.com/json-api-dotnet/JsonApiDotNetCore/pull/352/files#diff-967b2ba5f610a691c8d3f1b7ffbafe72L87

Need to improve API documentation so it is more clear what these methods do.

Also, need to add tests with compound (or just different) attribute names.

jaredcnance added a commit that referenced this issue Jul 26, 2018
Should consider creating a new API on the graph that is more intuitive and doesn't require both steps.
@jaredcnance jaredcnance changed the title Exception thrown if optional relationship is null Exception thrown if relationship name doesn't match navigation property name Jul 26, 2018
jaredcnance added a commit that referenced this issue Jul 26, 2018
Fix/#354: Null reference exception when fetching relationships with compound name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 participant