Realm on Android - How to select multiple objects by list of ids (@PrimaryKey)?

前端 未结 5 1256
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-18 21:25

I\'m building an Android app with the Realm database.

I have a RealmObject subclass called Article which has an id field (it\'s an

5条回答
  •  太阳男子
    2021-02-18 22:19

    The Realm Java API's doesn't support this yet unfortunately. You can follow the feature request here https://github.com/realm/realm-java/issues/841

    The current work-around would be to build up the query yourself in a for-loop:

    RealmResults
    articles = realm.allObjects(Article.class); RealmQuery q = articles.where(); for (int id : ids) { q = q.equalTo("id", id); } RealmResults
    filteredArticles = q.findAll();

提交回复
热议问题