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 convert from List to RealmList<RelmInt>?

See original GitHub issue

My model:

public class Company extends RealmObject {
 @PrimaryKey
 private long id;
 private RealmList<RealmInt> favorIds;
 private String address;
 private String email;
}

public class RealmInt extends RealmObject {
    private int value;
}

In Realm in field favorIds I has the next values:

[10, 20, 30]

And I need to update favorIds with [10,20,30,40] in Realm:

My steps:

  1. Delete favorIds
  2. add update list

Here code:

  realm.executeTransaction(new Realm.Transaction() {

 @Override
 public void execute(Realm realm) {
         List<Integer> favorsIds = CompanyService.getFavoritesIds(selectedCompanyID);
         favorsIds.add(40);
         Company company = realm.createObject(Company.class);
         company.getFavors().deleteAllFromRealm();
         company.getFavors().addAll(favorsIds);
    }
});

But I get compile error when try to add List<Integer> to RelmList<RealmInt>:

Cannot resolve method "addAll(java.util.List<java.lang.Integer>)"

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
Zhuindencommented, Sep 15, 2017

@lmdic one day you should tell me how you ended up with such a terrible Realm schema, just to sate my curiosity 😛

Of course, as it is a RealmInt, you need to construct a managed RealmInt and add that into the favorIds managed list

         List<Integer> favorsIds = CompanyService.getFavoritesIds(selectedCompanyID);
         favorsIds.add(40);
         Company company = realm.createObject(Company.class);
         RealmList<RealmInt> favors = company.getFavors();
         favors.deleteAllFromRealm();
         for(Integer favorId : favorsIds) {
              RealmInt realmInt = realm.createObject(RealmInt.class);
              realmInt.value = favorId;
              favors.add(realmInt);
         }
2reactions
Zhuindencommented, Sep 16, 2017

@lmdic welp, RealmList<Integer> should be available in about 2 weeks

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to convert realm list to RealmResults<Object>?
Solution: if you want to query on top of a RealmList, it should belong to a managed RealmObject, returned by a Realm instance....
Read more >
RealmList (Realm 10.10.1) - MongoDB
Returns true if the list contains the specified element when attached to a Realm. This method will query the native Realm underlying storage...
Read more >
Untitled
Sukkeleir, A list actors and actresses 2014, Top ten richest school districts in ... Bruchus lentis, Fiesta de santiago de huata 2013, Son-in-law...
Read more >
Untitled
Leonard nimoy big bang theory imdb, Los pacaminos, List three supreme court ... Ncaa 6th man of the year 2015, Pascal n/mm2 converter,...
Read more >
Untitled
Endeavour cast list home, Content based image retrieval using color and texture, ... 16 belmont avenue belfast, La nina julion alvarez free download!...
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