Extend @LinkingObjects feature to support queries.
This should work
public class Person extends RealmObject {
String name;
Dog dog;
}
public class Dog extends RealmObject {
String name;
@LinkingObjects("dog")
final RealmResults<Person> owners = null;
}
// Find all Dogs with at least one owner named John
realm.where(Dog.class).equalTo("owners.dog.name", "Fido").findAll();
RealmResults using Table::get_backlink_view() making something like cat.owners.where().equalTo("name", "John").findAll() possibleRealmQueryRealmQuery (equalTo() etc.) to allow querying backlinksRealm version(s): 3.1
We should also support the "dynamic query syntax": https://github.com/realm/realm-java/pull/2904/files#diff-b684aefe1e063faddcad9b319552f6e2R70
Use `linkingObjects(x.z).y` to search field Y on type X where X is a backlink object through Z.
@cmelchior oh, so this means that
RealmResults<Dog> dogs = realm.where(Dog.class).equalTo("linkingObjects(Person.dogs).name", "John").findAll();
in this particular scenario, Person has RealmList<Dog>, but Dog does NOT have @LinkingObjects("dogs") private final RealmResults<Person> owners but you can still query for essentially owners.dogs, except owners is unnamed so you need to specify it as linkingObjects(Person.dogs).name where the first part is essentially unnamed owners
Yes, it is a bit of a "power-feature", but is required when working with a DynamicRealm where a RealmModel class might not exist, like during a migration.
Using the named field is of course much much simpler, so should be used whenever possible.
@cmelchior the only pain part will be updating the realmfieldnameshelper :smile:
Actually, that would be fairly trivial, since it already works for RealmList. So for finding field names I just need to get the generic argument for a RealmResults instead of a RealmList 😝
@cmelchior i meant for the unnamed backlinks 👅
Yeah, RealmFieldNamesHelper is probably not going to support that, since it requires Realm model classes to even work :)
Is this in the works? This will be Realm's next killer feature
Yes, @bmeike is actively working on it.
Closing. C++ support being tracked in #4620
Most helpful comment
Yes, it is a bit of a "power-feature", but is required when working with a DynamicRealm where a RealmModel class might not exist, like during a migration.
Using the named field is of course much much simpler, so should be used whenever possible.