领域。根据外部元素获取内部元素的子集
Realm. Get subset of inner element based on outer one
有一个结构:
{ "groups": [
{ "gid" : 1,
"elements" : [
{ "eid" : 1 },
{ "eid" : 2 }
]
},
{ "gid" : 2,
"elements" : [
{ "eid" : 11 },
{ "eid" : 22 }
]
}
{ "gid" : 3,
"elements" : [
{ "eid" : 21 },
{ "eid" : 32 }
]
}
]
}
我了解如何获取所有组:
RealmResults<Group> all = realm.where(Group.class).findAll();
我还可以获取所有元素或一组中的所有元素。
但是我如何查询 id > 1 的组中的所有元素?
RealmResults<Group> allFilteredGroups = realm.where(Group.class).greaterThan("gid", 1).findAll();
是否可以通过一次查询从所有 allFilteredGroups
中检索所有元素,如
realm.where(Element.class).equalsTo(???, allFilteredGroups).findall() ?
我不太清楚你说的 "to retrieve all elements" 是什么意思。 allFilteredGroups
拥有所有 Group
个对象。由于它们链接到 Elements
对象,您可以轻松地遍历它们:
for(Group group : allFilteredGroups) {
for(Element element : group.getElement()) {
Log.d("TEST", "eid = " + element.eid);
}
}
目前没有简单的方法来展平最后一个并将所有 Element
个对象放在一个 RealmResults
中。
有一个结构:
{ "groups": [
{ "gid" : 1,
"elements" : [
{ "eid" : 1 },
{ "eid" : 2 }
]
},
{ "gid" : 2,
"elements" : [
{ "eid" : 11 },
{ "eid" : 22 }
]
}
{ "gid" : 3,
"elements" : [
{ "eid" : 21 },
{ "eid" : 32 }
]
}
]
}
我了解如何获取所有组:
RealmResults<Group> all = realm.where(Group.class).findAll();
我还可以获取所有元素或一组中的所有元素。
但是我如何查询 id > 1 的组中的所有元素?
RealmResults<Group> allFilteredGroups = realm.where(Group.class).greaterThan("gid", 1).findAll();
是否可以通过一次查询从所有 allFilteredGroups
中检索所有元素,如
realm.where(Element.class).equalsTo(???, allFilteredGroups).findall() ?
我不太清楚你说的 "to retrieve all elements" 是什么意思。 allFilteredGroups
拥有所有 Group
个对象。由于它们链接到 Elements
对象,您可以轻松地遍历它们:
for(Group group : allFilteredGroups) {
for(Element element : group.getElement()) {
Log.d("TEST", "eid = " + element.eid);
}
}
目前没有简单的方法来展平最后一个并将所有 Element
个对象放在一个 RealmResults
中。