Uploaded image for project: 'Realm Java SDK'
  1. Realm Java SDK
  2. RJAVA-73

RealmResults.collect()

      Sometimes you really want to get some other objects than the one you are querying. Example from link queries:

      • I want to find all Persons with a dog that is brown and called Fluffy.

      That is currently only possible when querying Persons:

      RealmResults<Owner> r2 = realm.where(Owner.class)
      .equalTo("dogs.name", "Fluffy")
      .findAll()
      .where()
      .equalTo("dogs.color", "Brown")
      .findAll();
      

      With a collect operator you could do instead:

      RealmResults<Owner> = realm.where(Dog.class)
        .equalTo("name", "Fluffy")
        .equalTo("color", "Brown")
        .findAll()
        .collectAll(Owner.class, "owner") // Dog needs a owner field
      

      Overriding findAll could also be an option, although I probably like the collect operator more as it is also a well known functional method.

      RealmResults<Owner> = realm.where(Owner.class)
        .equalTo("name", "Fluffy")
        .equalTo("color", "Brown")
        .findAll(Owner.class, "owner);
      

      What do you think @realm/java

      EDIT: Or maybe the above is just a symptom that the current query language are missing some features since findAll already is a collect statement, so we should fix that instead.

            Assignee:
            Unassigned Unassigned
            Reporter:
            christian.melchior@mongodb.com Christian Melchior (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: