Skip to content

Commit 24dd97c

Browse files
committed
refactor: tests passing again
1 parent 1420d6d commit 24dd97c

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ public virtual async Task<TEntity> UpdateAsync(TId id, TEntity entity)
242242
}
243243
else if (relationshipEntry.Key is HasOneAttribute hasOneAttribute)
244244
{
245+
//var foreignkeyValue = relationshipValue.GetType().GetProperty(hasOneAttribute.IdentifiablePropertyName).GetValue(oldEntity);
245246
hasOneAttribute.SetValue(oldEntity, relationshipValue);
246247
}
247248
}
@@ -405,7 +406,7 @@ private void AttachHasManyAndHasManyThroughPointers(TEntity entity)
405406
var tracked = AttachOrGetTracked(pointer);
406407
if (tracked != null) alreadyTracked = true;
407408
return tracked ?? pointer;
408-
});
409+
}).Cast(attribute.Type);
409410

410411
if (alreadyTracked) relationships[attribute] = (IList)newPointerCollection;
411412
}

src/JsonApiDotNetCore/Extensions/TypeExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ namespace JsonApiDotNetCore.Extensions
88
{
99
internal static class TypeExtensions
1010
{
11+
public static IEnumerable Cast(this IEnumerable source, Type type)
12+
{
13+
if (source == null) throw new ArgumentNullException(nameof(source));
14+
if (type == null) throw new ArgumentNullException(nameof(type));
15+
return TypeHelper.ConvertCollection(source.Cast<object>(), type);
16+
}
17+
1118
public static Type GetElementType(this IEnumerable enumerable)
1219
{
1320
var enumerableTypes = enumerable.GetType()

src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ private void SetHasOneForeignKeyValue(object entity, HasOneAttribute hasOneAttr,
250250

251251
var convertedValue = TypeHelper.ConvertType(foreignKeyPropertyValue, foreignKeyProperty.PropertyType);
252252
foreignKeyProperty.SetValue(entity, convertedValue);
253-
//_jsonApiContext.RelationshipsToUpdate[hasOneAttr] = convertedValue;
253+
if (convertedValue == null ) _jsonApiContext.HasOneRelationshipPointers.Add(hasOneAttr, null);
254254
}
255255
}
256256

0 commit comments

Comments
 (0)