查询 realmObject,其中 realmList 等于另一个 realmList

Query a realmObject where it realmList equals to another realmList

我想知道是否有直接的方法来查询 realmObjects 的 realmList 等于另一个 realmList。

示例:

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();

否,但您可以使用 in query condition 创建一个 link 查询。

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();