属性 属性 领域 select

Realm select by property of property

我有两个RealmModels

class Shop{

    private String name;
    private Item item;

}

class Item{
    private int itemId;
    private String itemName;
}

我想找到有 itemId = 1 商品的商店。

有什么想法吗?

您可以在 Realm 中跨引用(链接)进行查询。所以下面应该有效:

realm.where(Shop.class).equalTo("item.itemId", 1).findFirst()