Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List of EmbeddedObject no longer being returned with parent object. #3657

Closed
lamotuab opened this issue Jul 31, 2024 · 5 comments
Closed

List of EmbeddedObject no longer being returned with parent object. #3657

lamotuab opened this issue Jul 31, 2024 · 5 comments

Comments

@lamotuab
Copy link

lamotuab commented Jul 31, 2024

What happened?

I have Journal and JournalEntry classes per the definitions below. During startup, some sample data is created including 3 Journal objects each with either two or three JournalEntry objects attached. Subsequently, I use the following query to retrieve the list of Journals.

var journalList = new ObservableCollection<Journal>(_realm.All<Journal>().OrderBy(x => x.Date).ToList());

All three of the Journal objects retrieved have an empty Entries list (i.e. list count is zero).

I'm not sure which package upgrade caused this to stop working.

Repro steps

Interestingly though, if I migrate all objects to partial classes and use interfaces (i.e IRealmObject) it starts working again. However, this appears to bring heaps of pain with compiler nullability warnings left, right, and centre that I cannot seem to resolve.

Version

Realm 12.3.

What Atlas Services are you using?

Local Database only

What type of application is this?

Other

Client OS and version

macOS 14.5; NET MAUI 8; C# 12

Code snippets

public class Journal : RealmObject
{
    [PrimaryKey]
    [MapTo("_id")]
    public string Id { get; set; } = Guid.NewGuid().ToString();

    [MapTo("date")]
    public DateTimeOffset Date { get; set; }

    [MapTo("counterparty")]
    public Counterparty Counterparty { get; set; } = new ();

    [MapTo("memo")]
    public Memo? Memo { get; set; }

    [MapTo("reporting_group")]
    public ReportingGroup? ReportingGroup { get; set; }

    [MapTo("amount")]
    public decimal Amount { get; set; }

    [MapTo("entries")]
    public IList<JournalEntry> Entries { get; } = [];
}


public class JournalEntry : EmbeddedObject
{
    [MapTo("_id")]
    public string Id { get; set; } = Guid.NewGuid().ToString();

    [MapTo("account")]
    public Account Account { get; set; } = new();

    [MapTo("currency")]
    public Currency Currency { get; set; } = new();

    [MapTo("amount")]
    public decimal Amount { get; set; }

    [MapTo("is_credit")]
    public bool IsCredit { get; set; }
}

Stacktrace of the exception/crash you're getting

No response

Relevant log output

No response

Copy link

sync-by-unito bot commented Jul 31, 2024

➤ PM Bot commented:

Jira ticket: RNET-1171

@nirinchev
Copy link
Member

I think the issue here might be the default value for the list - can you try and remove it and see if that works?

@lamotuab
Copy link
Author

lamotuab commented Jul 31, 2024 via email

@nirinchev
Copy link
Member

I've tried to reproduce that and have not been successful. Here's my minimal attempt based on the models that you posted and that behaves as expected (re-running the application preserves the objects I've added). Can you try running it and if that works fine for you - try and modify it so that it triggers the behavior you're observing.

Issue3657.zip

@lamotuab
Copy link
Author

lamotuab commented Jul 31, 2024 via email

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants