领域查询具有特定值的字段的所有实体

时间:2016-11-12 23:11:47

标签: android realm

很抱歉,如果我的标题含糊不清,我不知道如何描述它。

我正在制作一个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 PerformanceEntity favorite的所有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(); 表没有主键。

我正在寻找的是与此(无效)查询类似的内容:

public int getDBPlacesCount() {
        String countQuery = "SELECT  * FROM " + TABLE_DB_VERLADESTELLEN_Eintrag;
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery(countQuery, null);
        cursor.close();

        // return count
        return cursor.getCount();
    }

1 个答案:

答案 0 :(得分:3)

实际上,我认为您的用例是以下查询:

func collectionView(collectionView: UICollectionView, layout
    collectionViewLayout: UICollectionViewLayout,
    minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
        return 1.0
}

请检查我是否正确,link queries总是让我困惑。

相关问题