Open cmelchior opened 8 years ago
I think there are tow very distinct use cases here. One is grouping because you need the objects within each group (like in segmented view), and the other one is the aggregates, which is more of a pivot table functionality.
The pivot table functionality is actually likely to be the easiest to implement, as there already are native support for that in core.
The grouping is a bit more difficult, mostly because of the question of what you should return. The most natural would be a RealmResults
containing a new type, composed of the value being grouped on and a RealmList
of the matching objects. This would either have to be accessed with the dynamic API, or the user should predeclare a matching type:
public class PersonGroupByAge extends RealmObject {
private int age;
private RealmList<Person> persons;
}
RealmResults< PersonGroupByAge > ages = realm.where(Person.class).groupBy("age").findAll();
Is this issue Resolved now?
We should add support for GROUP BY. Not entirely sure about the API as you usually want to supply a aggregate function at the same time. Also the return type will be a bit tricky, as the data is a lot more dynamic (and DynamicRealmObject doesn't fit). If we had a Sorted RealmMap it might make sense, although exposing as a List would probably be the more expected.
http://stackoverflow.com/questions/35533550/is-it-possible-to-use-group-by-concept-in-realm-mobile-database