Skip to content

Commit ed223c1

Browse files
committed
ensure pointers are attached prior to adding the entity
1 parent 1062ea9 commit ed223c1

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@ public virtual async Task<TEntity> GetAndIncludeAsync(TId id, string relationshi
8484

8585
public virtual async Task<TEntity> CreateAsync(TEntity entity)
8686
{
87+
AttachHasManyPointers();
8788
_dbSet.Add(entity);
8889

89-
DetachHasManyPointers();
90-
9190
await _context.SaveChangesAsync();
9291
return entity;
9392
}
@@ -96,7 +95,7 @@ public virtual async Task<TEntity> CreateAsync(TEntity entity)
9695
/// This is used to allow creation of HasMany relationships when the
9796
/// dependent side of the relationship already exists.
9897
/// </summary>
99-
private void DetachHasManyPointers()
98+
private void AttachHasManyPointers()
10099
{
101100
var relationships = _jsonApiContext.HasManyRelationshipPointers.Get();
102101
foreach(var relationship in relationships)

0 commit comments

Comments
 (0)