Model reference becomes null after adding to a different model relation
See original GitHub issueSummary
With the code below it can be seen that I have an Account
: Program
relation as well as Account
: []Account
. The Program
can be accessed through the Account
until a new relation is added, after that I the account.program
is immediately null. Using stetho it can be seen that the program is now a null value.
Account
class Account {
public Program program;
public RealmList<Account> following;
}
Follow account
// ...
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
Account currentUser = realm.where(Account.class)
.equalTo(Account.ATTR_KEY, Session.getAccountKey(context))
.findFirst();
Account a = resp.body(); // account's program is not null here
Log.d("program", currentUser.program.name); // shows the program name
currentUser.following.add(a); // results in Account -> Program disconnect
Log.d("program", currentUser.program.name); // null pointer exception
}
});
// ...
Version of Realm and tooling
Realm version(s): 2.0.2
Android Studio version: ? 2.2.1
Which Android version and device: ? 4.2.1 Galaxy Nexus
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Laravel Eloquent 'with' returns null, but referencing the ...
I'd love to understand why the filtered relationship works fine when calling the relationship method but not using 'with'. – Andrew. Apr 14, ......
Read more >Working with nullable reference types - EF Core
C# 8 introduced a new feature called nullable reference types (NRT), allowing reference types to be annotated, indicating whether it is ...
Read more >Detect if `belongsTo` is null, and toggle associations - Ember.JS
I am missing something about how to determine if a belongsTo relationship on a model is set. And how I can toggle that...
Read more >Data model (Reference) - Prisma
Learn about the concepts for building your data model with Prisma: Models, scalar types, enums, attributes, functions, IDs, default values and more.
Read more >attempt to de-reference null object when using maps to build ...
So adjacentGroup must be null. That variable is set from the result of groupsMap.get(o.PDC__c) . The issue you're running into is that ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You are right in regards to the account payload from
resp.body()
not containing the program and then deleting it.Performing a realm lookup for the account, then adding that account reference works.
Sorry for the post here, I thought it was a bug 😦
Well considering you overrode the original
currentUser
as the proxy pointed to the same object, it’s no wonder the error looked so arcane 🙂