【问题标题】:Realm Query possible to use IN? [duplicate]可以使用 IN 的领域查询吗? [复制]
【发布时间】:2015-07-05 04:41:52
【问题描述】:

我有以下领域查询,但通过阅读文档,我看不到进行 IN 查询的可能性。

我需要在包含该 id 的字符串或数组中搜索 id。这可能吗?

示例代码:

Realm realmThread = Realm.getInstance(visnetawrap.appModel);
RealmResults<PropertyObject> propResults = realmThread.where(PropertyObject.class).contains("propertyID", "(5,7,10)").findAll();

【问题讨论】:

    标签: android realm


    【解决方案1】:

    恐怕我指出的很明显,但你可以链接ored equalTos。

    RealmQuery<PropertyObject> query = realm.where(PropertyObject.class);
    query.beginGroup();
    for(int i = 0; i < propertyIDs.length - 1; i++) {
        query.equalTo("propertyID", propertyIDs[i]).or();
    }
    
    query.equalTo("propertyID", propertyIDs[propertyIDs.length - 1]).endGroup();
    RealmResults<PropertyObject> propResults = query.findAll();
    

    【讨论】:

    • in 功能已经是requested。其中一位作者(?)提出了类似的解决方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多