Skip to content

Commit 1ce6b69

Browse files
authored
Merge pull request #93 from lyallo/issue-92
Track Tag entity when editing an article so that it doesn't attempt to insert any duplicate tags
2 parents 94e4616 + ef94699 commit 1ce6b69

File tree

1 file changed

+4
-0
lines changed
  • src/Conduit/Features/Articles

1 file changed

+4
-0
lines changed

src/Conduit/Features/Articles/Edit.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ public async Task<ArticleEnvelope> Handle(Command message, CancellationToken can
7878
article.UpdatedAt = DateTime.UtcNow;
7979
}
8080

81+
// ensure context is tracking any tags that are about to be created so that it won't attempt to insert a duplicate
82+
_context.Tags.AttachRange(articleTagsToCreate.Select(a => a.Tag).ToArray());
83+
8184
// add the new article tags
8285
await _context.ArticleTags.AddRangeAsync(articleTagsToCreate, cancellationToken);
86+
8387
// delete the tags that do not exist anymore
8488
_context.ArticleTags.RemoveRange(articleTagsToDelete);
8589

0 commit comments

Comments
 (0)