如何搜索 RealmObj 的 RealmList 字段

huangapple go评论73阅读模式
英文:

How to search RealmList field of RealmObj

问题

我有一个类似这样的 Realm 对象:

public class Person extends RealmObject {

private String fullName;
private RealmList<PhoneNumberObj> phoneNumbers;}

其中 PhoneNumberObj 类的结构如下:

public class PhoneNumberObj extends RealmObject {

private String phoneNumber;
private String type;
}

是否可以使用 Realm 查询来查找具有特定 phoneNumber 的人?

英文:

I have a realm object like:

public class Person extends RealmObject {

private String fullName;
private RealmList&lt;PhoneNumberObj&gt; phoneNumbers;}    

Where the class PhoneNumberObj looks like:

public class PhoneNumberObj extends RealmObject {

private String phoneNumber;
private String type;
}

Is it possible to use a realm query to find a person with a specific phoneNumber?

答案1

得分: 1

当然,使用链接查询

RealmResults<Person> persons = realm.where(Person.class)
                                   .equalTo("phoneNumbers.phoneNumber", phoneNumber)
                                   .findAllAsync();
英文:

Sure, using a link query

RealmResults&lt;Person&gt; persons = realm.where(Person.class)
                                   .equalTo(&quot;phoneNumbers.phoneNumber&quot;, phoneNumber)
                                   .findAllAsync();

huangapple
  • 本文由 发表于 2020年8月19日 07:05:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63477821.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定