2016-11-12 83 views
2

對不起,如果我的標題含糊不清,我不知道如何描述它。領域查詢所有具有特定值的字段的實體

我正在製作一個Android應用程序,用戶可以在該應用程序中瀏覽節日中的事件列表,單擊它們以獲取有關該事件的更詳細概述及其性能時間。

這裏是我的Java模型:

public class FestivalEntity extends RealmObject { 
    @PrimaryKey 
    public String code; 
    public String description; 
    public String title; 
    public int minimumAge; 
    public String squareImage; 
    public String landscapeImage; 
    public RealmList<PerformanceEntity> performances; 
    public Date firstPerformance; 
} 

public class PerformanceEntity extends RealmObject { 
    public Date start; 
    public Date end; 
    public double price; 
    public boolean favorite; 
} 

我的問題是:我怎麼做是查找所有FestivalEntity S作一個PerformanceEntityfavorite查詢?我無法選擇個人PerformanceEntity,因爲PerformanceEntity表沒有主鍵。

我所尋找的是類似這樣(無效)查詢的內容:

//Should return a list of FestivalEntity's that contain at least one performance that is favorite 
RealmResults<FestivalEntity> results = realm.where(FestivalEntity.class).any("performances.favorite", true).findAll(); 

回答

3

其實,我覺得您的使用情況是下面的查詢:

RealmResults<FestivalEntity> results = realm.where(FestivalEntity.class) 
    .equalTo("performances.favorite", true) 
    .findAll(); 

請檢查,如果我不過,link queries總是讓我困惑。

相關問題