Skip to content

Commit 652d65f

Browse files
committed
fix: resource separation issue|
1 parent 7aea60c commit 652d65f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,20 +257,28 @@ private object GetTrackedRelationshipValue(RelationshipAttribute relationshipAtt
257257
}
258258
}
259259

260+
// helper method used in GetTrackedRelationshipValue. See comments there.
260261
private IList GetTrackedManyRelationshipValue(IEnumerable<IIdentifiable> relationshipValueList, RelationshipAttribute relationshipAttr, ref bool wasAlreadyAttached)
261262
{
262263
if (relationshipValueList == null) return null;
263264
bool _wasAlreadyAttached = false;
265+
Type entityType = null;
264266
var trackedPointerCollection = relationshipValueList.Select(pointer =>
265267
{
268+
/// todo: we can't just use relationshipAttr.Type because
269+
/// this will point to the Resource type in the case of entity resource
270+
/// separation. We should consider to store entity type on
271+
/// the relationship attribute too.
272+
entityType = entityType ?? pointer.GetType();
266273
var tracked = AttachOrGetTracked(pointer);
267274
if (tracked != null) _wasAlreadyAttached = true;
268-
return Convert.ChangeType(tracked ?? pointer, relationshipAttr.Type);
269-
}).ToList().Cast(relationshipAttr.Type);
275+
return Convert.ChangeType(tracked ?? pointer, entityType);
276+
}).ToList().Cast(entityType);
270277
if (_wasAlreadyAttached) wasAlreadyAttached = true;
271278
return (IList)trackedPointerCollection;
272279
}
273280

281+
// helper method used in GetTrackedRelationshipValue. See comments there.
274282
private IIdentifiable GetTrackedHasOneRelationshipValue(IIdentifiable relationshipValue, HasOneAttribute hasOneAttribute, ref bool wasAlreadyAttached)
275283
{
276284

0 commit comments

Comments
 (0)