question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How create not required RealmList property

See original GitHub issue

Android client: Realm version: 4.1.0 ROS ver. 2.8.0 Realm Studio ver. 1.18.5

Organization is create in Realm by import from json.

Here POJO.

public class Organization extends RealmObject {
    @PrimaryKey
    private long id;
    private boolean ready = false;
    @Required
    private String name;
    private RealmList<RealmInt> recommendations;
}

public class RealmInt extends RealmObject {
  private int value;
}

When first time import orgranization from json the property recommendations is missing. First time the organization can not contain recommendations. It’s a normal situation. The recommendations can be update later. From another json. That is a reason why I create property recommendations WITHOUT annotation @Required.

So I start my android app and login by admin credentials (download/upload). And as result it’s sync with ROS. As result on ROS success created my custom realm with all tables. Nice. Now in Realm Studio I save model definition in java format. And as result I get the next Organizaion.java

public class Organization extends RealmObject {
    @PrimaryKey
    private long id;
    private boolean ready = false;
    @Required
    private String name;
    @Required
    private RealmList<RealmInt> recommendations;
}

public class RealmInt extends RealmObject {
  private int value;
}

As you can see the property recommendations now has annotation @Required. Why? As I describe earlier this is not required field.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cmelchiorcommented, Mar 4, 2018

I have updated Realm Studio, so you can no longer set the nullability status of lists when referencing model classes. This should prevent this situation from happening in the future. It will be in the next release of Realm Studio

0reactions
Zhuindencommented, Mar 1, 2018

@Required never did anything on a RealmList<T extends RealmModel>. It has no effect. That list cannot store nulls. It never could.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prevent of creating realm object while saving in RealmList
it seems saving a product RealmList in StoreTransaction class creates new data in Product class. Is there a way to prevent this? i'm...
Read more >
RealmList Constructor? - Realm - MongoDB
Not exactly… ? A List is a property of a Realm Object. To use a List, you would need to add a List...
Read more >
RealmList<RealmString> is an anti-pattern! - Medium
1.) You need to define a new RealmObject for it. You need to create a RealmObject for something that isn't really meant to...
Read more >
Realm Xamarin 0.73.0
Simply subclass RealmObject to create your Realm data model objects. ... You can define a to-many relationship using RealmList properties.
Read more >
Realm List's New Superpowers - Realm Academy
One of the most requested features from developers has been the ability to store simple values in Realm's List class. That's one of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found