Skip to content

Commit 6da3fa4

Browse files
committed
Bypass unsaved relationships (bug fix)
In a recent commit (d0a96d8), I updated `PersistRelationships()` to bypass unsaved relationships. Except, that's not actually what I did. That code had an error in it, as it was evaluating the _source_ topic, not the _target_ topic. Whoops. This resolves that issue. See d0a96d8 for an explanation on the objective for this change. The short of it is that we shouldn't save references to targets that don't have a `TopicId` as that will generate a FKC exception in the database. This only happens in rare scenarios, but one notable example is when recursively saving entire topic in-memory topic graphs, as happens when importing topics.
1 parent 682d328 commit 6da3fa4

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -585,16 +585,11 @@ private static string PersistRelations(Topic topic, SqlConnection connection, bo
585585
var scope = topic.Relationships.GetTopics(key);
586586
var topicId = topic.Id.ToString(CultureInfo.InvariantCulture);
587587

588-
//Relationship hasn't been saved yet; cannot persist
589-
if (topic.Id < 0) {
590-
continue;
591-
}
592-
593588
command = new SqlCommand("UpdateRelationships", connection) {
594589
CommandType = CommandType.StoredProcedure
595590
};
596591

597-
foreach (var targetTopicId in scope.Select<Topic, int>(m => m.Id)) {
592+
foreach (var targetTopicId in scope.Where(t => t.Id > 0).Select<Topic, int>(m => m.Id)) {
598593
var record = targetIds.NewRow();
599594
record["TopicID"] = targetTopicId;
600595
targetIds.Rows.Add(record);

0 commit comments

Comments
 (0)