Skip to content

Commit

Permalink
Merge pull request #106 from Research-Institute/hotfix/null-ref-include
Browse files Browse the repository at this point in the history
fix null ref on GetRelationshipsAsync
  • Loading branch information
jaredcnance authored May 12, 2017
2 parents 9daab2e + 5ef646b commit c5bcaad
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore/Internal/ContextGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public string GetRelationshipName<TParent>(string relationshipName)
e.EntityType == entityType)
.Relationships
.FirstOrDefault(r =>
r.InternalRelationshipName.ToLower() == relationshipName.ToLower())
r.PublicRelationshipName.ToLower() == relationshipName.ToLower())
?.InternalRelationshipName;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore/JsonApiDotNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>2.0.2</VersionPrefix>
<VersionPrefix>2.0.3</VersionPrefix>
<TargetFrameworks>netstandard1.6</TargetFrameworks>
<AssemblyName>JsonApiDotNetCore</AssemblyName>
<PackageId>JsonApiDotNetCore</PackageId>
Expand Down
4 changes: 3 additions & 1 deletion src/JsonApiDotNetCore/Services/EntityResourceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public async Task<object> GetRelationshipAsync(TId id, string relationshipName)
if (relationshipName == null)
throw new JsonApiException("422", "Relationship name not specified.");

_logger.LogTrace($"Looking up '{relationshipName}'...");

var entity = await _entities.GetAndIncludeAsync(id, relationshipName);
if (entity == null)
throw new JsonApiException("404", $"Relationship {relationshipName} not found.");
Expand All @@ -116,7 +118,7 @@ public async Task<T> UpdateAsync(TId id, T entity)
public async Task UpdateRelationshipsAsync(TId id, string relationshipName, List<DocumentData> relationships)
{
relationshipName = _jsonApiContext.ContextGraph
.GetRelationshipName<T>(relationshipName.ToProperCase());
.GetRelationshipName<T>(relationshipName);

if (relationshipName == null)
throw new JsonApiException("422", "Relationship name not specified.");
Expand Down

0 comments on commit c5bcaad

Please sign in to comment.