objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
999 stars 117 forks source link

Add link and linkMany methods logical operator parameter #464

Open bahadirarslan opened 2 years ago

bahadirarslan commented 2 years ago

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.

@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?

greenrobot-team commented 2 years ago

Thanks for the request! Please thumbs up the first post, if you are interested in this.

Note: there is also an issue for the Java library: https://github.com/objectbox/objectbox-java/issues/497