objectbox / objectbox/objectbox-dart

Add link and linkMany methods logical operator parameter

Open
#464 2 comments 14 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Dart
Stars
1.2k
Forks
162
Avg merge
15m
Merged PRs (30d)
1

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the QueryBuilder.link and linkMany APIs and the relation-query documentation referenced in the issue. Reproduce the shown Person and Address query, then determine how an OR condition between the person name and linked address should be expressed. Done means relation queries can support the requested OR behavior without losing the existing AND behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.