-
Type: Bug
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
3 - M (<= 1 month)
-
2662
What happened?
In conforming to c# 9 nullability, realm models using one-to-many relationships need a value assigned to their get-only list properties to make the compiler happy. My initial approach was to initialise these with a new list:
public class RealmBeatmapSet : RealmObject { public Guid ID { get; set; } = Guid.NewGuid(); public IList<RealmBeatmap> Beatmaps { get; } = new List<RealmBeatmap>(); }
As it turns out, doing this means even though storing a newly created model works as expected, retrieving an existing object from a realm instance will never show any relations. The fix is easy enough - suppressing null and leaving it to the underlying realm initialisation to make the empty lists works as expected:
public class RealmBeatmapSet : RealmObject { public Guid ID { get; set; } = Guid.NewGuid(); public IList<RealmBeatmap> Beatmaps { get; } = null!; }
But this does feel like an easy slip-up to make as a user, and there is no errors or warning as to what is going on.
Repro steps
- Initialise an {{IList<T> x
{get;}
}} with a construction-time value
- Attempt to access a nested object via this relation
Version
10.5.0
What SDK flavour are you using?
Local Database only
What type of application is this?
Console/Server
Client OS and version
macOS 12
Code snippets
No response
Stacktrace of the exception/crash you're getting
No response
Relevant log output
No response