领域。获取基于外部元素的内部元素的子集

时间:2015-12-02 21:43:37

标签: realm nosql

有一个结构:

{ "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为&gt;的组中的所有元素? 1?

RealmResults<Group> allFilteredGroups = realm.where(Group.class).greaterThan("gid", 1).findAll();

是否可以通过一个查询从所有allFilteredGroups中检索所有元素,如

realm.where(Element.class).equalsTo(???, allFilteredGroups).findall() ?

1 个答案:

答案 0 :(得分:0)

我不太确定你的意思是&#34;检索所有元素&#34;。 allFilteredGroups包含所有Group个对象。由于它们与Elements对象相关联,因此您可以轻松地遍历它们:

for(Group group : allFilteredGroups) {
    for(Element element : group.getElement()) {
        Log.d("TEST", "eid = " + element.eid);
    }
}

目前还没有简单的方法来展平最后一个并将Element个所有RealmResults个对象放在一个SQL query: Dumping data for table data INSERT INTO `data` (`id`, `name`, `dt`, `console`, `age`) VALUES (1, 'abc', '1/june/2015', 'abc','123'), ; MySQL said: Documentation 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6 中。