I am using Objectbox for my several projects; this time, I need to build a complex query.
Currently, objectbox offers quite good tools for this but if the relations are on the table there are stringent restrictions.
For example, let's continue with the official example about queries with relations.
here are our entities.
@Entity()
class Person {
int id;
String name;
final addresses = ToMany<Address>();
}
@Entity()
class Address {
int id;
String street;
String zip;
}
If you want to query any record you should use the code below.
// get all Person objects named "Elmo"...
QueryBuilder<Person> builder = personBox
.query(Person_.name.equals('Elmo'));
// ...which have an address on "Sesame Street"
builder.linkMany(Person_.addresses, Address_.street.equals('Sesame Street'));
Query<Person> query = builder.build();
List<Person> elmosOnSesameStreet = query.find();
query.close();
This code returns the person whose name is Elmo and also his address is Sesame Street.
The problem is also, what if you want to retrieve people name Ricky or anyone whose address is Sesame Street? I checked the documentation and the internet but finally, I decided that there is no way to use relations with OR condition. They are always working with AND conditions.
So is it possible to add a parameter to link and linkMany methods for AND or OR operator?
Hi All,
I am using Objectbox for my several projects; this time, I need to build a complex query. Currently, objectbox offers quite good tools for this but if the relations are on the table there are stringent restrictions.
For example, let's continue with the official example about queries with relations. here are our entities.
If you want to query any record you should use the code below.
This code returns the person whose name is Elmo and also his address is Sesame Street. The problem is also, what if you want to retrieve people name Ricky or anyone whose address is Sesame Street? I checked the documentation and the internet but finally, I decided that there is no way to use relations with OR condition. They are always working with AND conditions.
So is it possible to add a parameter to link and linkMany methods for AND or OR operator?