Search code examples
androidrealmrealm-list

Query a realmObject where it realmList equals to another realmList


I would like to know if there is a direct way to query realmObjects where its realmList equals another realmList.

Example:

public class Tags extends RealmObject{
    @PrimaryKey
    private String ID = UUID.randomUUID().toString();

    private String tag;
}

public class Article extends RealmObject {
    @PrimaryKey
    private String ID = UUID.randomUUID().toString();

    private RealmList<Tags> tags;
}

RealmList<Tags> userTags;
Article article = mDB.where(Article.class).equalTo("tags", userTags).findFirst();

Solution

  • No, but you can create a link query with in query condition.

    RealmList<Tags> userTags = ...;
    Set<String> tags = new LinkedHashSet<>();
    for(Tags tag : userTags) {
        ids.add(tag.getTag());
    }
    String[] tagArray = tags.toArray(new String[tags.size()]);
    Article article = mDB.where(Article.class).in("tags.tag", tagIdArray).findFirst();