Realm Android 嵌套查询 [英] Realm Android Nested Query

查看:47
本文介绍了Realm Android 嵌套查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于以下类和关系,我需要一个 RealmResults <满足以下要求的模型 1 >:

Given the below classes and relationships, I need a RealmResults < Model1 > that satisfies the following requirements:

模型 1

int id
RealmList<Model2>

模型 2

int id
int model1Fk
int type
RealmList<Model3>

Model3

int model2Fk

我想查询所有 Model1 实体,对于特定的 Model2 相关实例类型,该 Model2 实例至少有一个 Model3 相关实例.

I want to query all the Model1 entities that, for a specific Model2 related instance type, that Model2 instance has at least one Model3 related instance.

在 SQL 中(尚未测试):

In SQL that would be (Haven't tested it):

select distinct model1.*
from Model1 model1 join Model2 model2 on model2.model1Fk = model1.id join Model3 model3 on model3.model2Fk = model2.id
where model2.type = 'Some Type'

推荐答案

你的文字描述和加入不匹配,但是如果你想找到所有带有Model2Model1Some type的code>,你可以执行以下操作:

Your text description and join doesn't match, but if you want to find all Model1 with a Model2 of Some type, you can do the following:

realm.where(Model1.class).equalTo("model2List.type", "Some Type").findAll();

您可以在此处阅读有关链接查询的信息:https://realm.io/docs/java/latest/#link-queries.

You can read about link queries here: https://realm.io/docs/java/latest/#link-queries.

如果你想找到所有 Model1 至少有 1 个 Model2 并且至少有一个 Model3 有某个值,你可以执行以下操作:

If you want to find all Model1 which have at least 1 Model2 that also have at least one Model3 with some value, you can do the following:

realm.where(Model1.class).equalTo("model2List.Model3List.model2Fk", "some model2Fk value").findAll();

这篇关于Realm Android 嵌套查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆