Skip to content

Commit 84e9e04

Browse files
committed
fix(DocumentBuilder): use the new GetRelationshipValue API
1 parent 7adc1db commit 84e9e04

File tree

3 files changed

+3
-29
lines changed

3 files changed

+3
-29
lines changed

src/Examples/JsonApiDotNetCoreExample/Models/Tag.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace JsonApiDotNetCoreExample.Models
44
{
55
public class Tag : Identifiable
66
{
7-
[Attr("name")]
7+
[Attr]
88
public string Name { get; set; }
99
}
1010
}

src/JsonApiDotNetCore/Builders/DocumentBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private List<ResourceObject> IncludeRelationshipChain(
217217
if(relationship == null)
218218
throw new JsonApiException(400, $"{parentEntity.EntityName} does not contain relationship {requestedRelationship}");
219219

220-
var navigationEntity = _jsonApiContext.ContextGraph.GetRelationship(parentResource, relationship.InternalRelationshipName);
220+
var navigationEntity = _jsonApiContext.ContextGraph.GetRelationshipValue(parentResource, relationship);
221221
if (navigationEntity is IEnumerable hasManyNavigationEntity)
222222
{
223223
foreach (IIdentifiable includedEntity in hasManyNavigationEntity)

src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,7 @@ public virtual IQueryable<TEntity> Include(IQueryable<TEntity> entities, string
321321
entity = _jsonApiContext.ContextGraph.GetContextEntity(relationship.Type);
322322
}
323323

324-
IQueryable<TEntity> included = entities.Include(internalRelationshipPath);
325-
AttachHasManyThrough(relationshipChain, included);
326-
return included;
324+
return entities.Include(internalRelationshipPath);
327325
}
328326

329327
/// <inheritdoc />
@@ -370,29 +368,5 @@ public async Task<IReadOnlyList<TEntity>> ToListAsync(IQueryable<TEntity> entiti
370368
? await entities.ToListAsync()
371369
: entities.ToList();
372370
}
373-
374-
private void AttachHasManyThrough(string[] relationshipChain, IQueryable<TEntity> included)
375-
{
376-
var hasManyThroughRelationships = _jsonApiContext.RequestEntity.Relationships.OfType<HasManyThroughAttribute>();
377-
foreach (var hasManyThroughRelation in _jsonApiContext.RequestEntity.Relationships.OfType<HasManyThroughAttribute>())
378-
{
379-
if (relationshipChain.Contains(hasManyThroughRelation.PublicRelationshipName))
380-
{
381-
Type rightInstancesListType = typeof(List<>).MakeGenericType(hasManyThroughRelation.Type);
382-
PropertyInfo rightPropertyOnLeft = _jsonApiContext.RequestEntity.EntityType.GetProperty(hasManyThroughRelation.InternalRelationshipName);
383-
foreach (var leftInstance in included)
384-
{
385-
var rightInstancesList = (IList)Activator.CreateInstance(rightInstancesListType);
386-
var throughInstances = (IList)hasManyThroughRelation.ThroughProperty.GetValue(leftInstance);
387-
foreach (var ti in throughInstances)
388-
{
389-
var rightInstance = hasManyThroughRelation.RightProperty.GetValue(ti);
390-
rightInstancesList.Add(rightInstance);
391-
}
392-
rightPropertyOnLeft.SetValue(leftInstance, rightInstancesList);
393-
}
394-
}
395-
}
396-
}
397371
}
398372
}

0 commit comments

Comments
 (0)