Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在子对象上聚合_Android_Database_Realm_Realm Mobile Platform - Fatal编程技术网

Android 在子对象上聚合

Android 在子对象上聚合,android,database,realm,realm-mobile-platform,Android,Database,Realm,Realm Mobile Platform,例外情况是,不支持链接对象字段上的聚合。你需要自己计算 试试这个: java.lang.IllegalArgumentException: Aggregates on child object fields are not supported: ChallengeTargetDB.targetValue 使用Realm 3.5.0+ Number max = null; for (ChallengeDB item : challengeDBs) { if (max == null) {

例外情况是,不支持链接对象字段上的聚合。你需要自己计算

试试这个:

java.lang.IllegalArgumentException: Aggregates on child object fields are not supported: ChallengeTargetDB.targetValue
使用Realm 3.5.0+

Number max = null;
for (ChallengeDB item : challengeDBs) {
    if (max == null) {
        max = item.ChallengeTargetDB.max();
    } else {
        Number tmp = item.ChallengeTargetDB.max();
        max = max.longValue() > tmp.longValue() ? max : tmp;
    }
}
public类ChallengeTargetDB扩展RealmObject{
@主键
私人int targetId;
私有字符串targetName;
私有字符串描述;
私人长期目标价值;
私人int targetStep;
私有布尔值通过;
@链接对象(“ChallengeTargetDb”)
private final RealmResults targetOfChallenge=null;
}
然后

RealmResults challengeDBs=realm.where(ChallengeTargetDB.class)
.equalTo(“targetOfChallenge.”+workoutcashcontents.COLUMN_challenged_ID,challengeDB.getChallengeId()).findAll();
long max=challengeDBs.max(“targetValue”).longValue();

我已经使用类似的方法获得了最大值。但我的问题是,这是否是一个功能请求?如果是,我是否也需要提供链接对象的迁移?如何避免@LinkingObject导致迁移,因为它们实际上不是架构的一部分。很抱歉,这么晚才回复您,我正在做其他事情。升级领域版本和链接对象都很好。非常感谢你的帮助。
java.lang.IllegalArgumentException: Aggregates on child object fields are not supported: ChallengeTargetDB.targetValue
Number max = null;
for (ChallengeDB item : challengeDBs) {
    if (max == null) {
        max = item.ChallengeTargetDB.max();
    } else {
        Number tmp = item.ChallengeTargetDB.max();
        max = max.longValue() > tmp.longValue() ? max : tmp;
    }
}
public class ChallengeTargetDB extends RealmObject {
    @PrimaryKey
    private int targetId;
    private String targetName;
    private String description;
    private long targetValue;
    private int targetStep;
    private boolean isPassed;

    @LinkingObjects("ChallengeTargetDb")
    private final RealmResults<ChallengeDb> targetOfChallenge = null;
  }
 RealmResults<ChallengeTargetDB> challengeDBs = realm.where(ChallengeTargetDB.class)
                .equalTo("targetOfChallenge." + WorkoutCashConstants.COLUMN_CHALLENGE_ID, challengeDB.getChallengeId()).findAll();

        long max = challengeDBs.max("targetValue").longValue();