2015-07-05 17 views
8

Tôi có truy vấn lĩnh vực sau đây nhưng từ đọc tài liệu tôi không thấy khả năng thực hiện truy vấn IN.Truy vấn lĩnh vực có thể sử dụng IN?

Tôi cần tìm kiếm id trong chuỗi hoặc mảng chứa id đó. Điều này có thể không?

Ví dụ mã:

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

Trả lời

2

Tôi sợ rằng tôi đang chỉ ra rõ ràng, nhưng bạn có thể chuỗi or ed equalTo s.

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(); 
+1

Tính năng 'in' đã được yêu cầu (https://github.com/realm/realm-java/issues/841). Và một trong những tác giả (?) Cho thấy một cách giải quyết tương tự. –

Các vấn đề liên quan