Commit 1e9152a
committed
Reevaluate
If a `DerivedTopic` is set prior to it being saved, the `DerivedTopic.Id` won't be persisted as a `TopicID` attribute in the `Topic.Attributes` collection. This is by design to prevent an invalid relationship from being persisted to the underlying data store (a3b6da1).
The problem with this, however, is that the `Topic` has no (current) way of knowing when the target `DerivedTopic` has been saved, and thus its underlying `TopicID` attribute will remain unset even after the `DerivedTopic` has received a valid `Topic.Id`. To mitigate this, the `TopicRepositoryBase.Save()` method now sets `DerivedTopic` to itself. If the `Id` has changed—i.e., if the `Id` has been set—then that will cause it to be persisted to the `Topic.Attributes` collection and subsequently persisted to the underlying data storage.
This fixes a bug that occurred when recursively saving in-memory topic graphs, as otherwise `DerivedTopic`s would only be persisted if either a) they were saved before the source class, or b) the `DerivedTopic` relationship was reestablished before a subsequent `Save()`. This is exactly how e.g. the **OnTopic Editor** works with the **OnTopic Data Transfer** library—but we shouldn't rely on implementors knowing this. By baking this into `Save()`, we help prevent unintuitive results when working with these scenarios.DerivedTopic on Save()
1 parent a3b6da1 commit 1e9152a
1 file changed
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
307 | 318 | | |
308 | 319 | | |
309 | 320 | | |
| |||
0 commit comments