【问题标题】:Query a realmObject where it realmList equals to another realmList查询其 realmList 等于另一个 realmList 的 realmObject
【发布时间】:2017-06-12 11:17:55
【问题描述】:

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

例子:

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

【问题讨论】:

  • 你从哪里得到userTags?它是否属于名为 User 的 RealmObject?
  • 不一定。该应用程序有一个搜索引擎,用户可以在其中插入标签以查找文章。我想返回所有符合该标签标准的文章。有什么想法吗?

标签: android realm realm-list


【解决方案1】:

否,但您可以使用 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();

【讨论】:

  • 酷,我认为它可以工作,让我试试并测试它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多