0

I have a simple structure like this, one Person with many Orders.

If a Person has placed many Orders (with codes 1,2 or 3) how do you return Persons with Orders that match only code 3 i.e.: they haven't ordered 1 or 2?

If I have the code below this will match Persons that have Orders with codes 1,2,3 and 2,3 etc yet I only want Persons that have Order matching code 3.

  1. Person (Match)

    Order code = 3

  2. Person

    • Order code = 1
    • Order code = 2
    • Order code = 3
  3. Person

    • Order code = 2
    • Order code = 3

QueryBuilder <Person> builder = getBox().query();

builder.linkMany(
  Person_.orders,
  Order_.code.equals(3));


// or this...

builder.linkMany(
  Person_.orders,
  Order_.code
  .equals(3)
  .and(Order_.code.notEquals(1)).and(Order_.code.notEquals(2)));

final query = builder.build()
  ..offset = page
  ..limit = limit;

List <Person> persons = query.find();

I'm sure I am missing something simple here!

Fuxster
  • 1
  • 1
  • Sorry, I can't really think of a condition that would work (see https://docs.objectbox.io/queries#notable-conditions). An owning object is returned if a single related object matches. Maybe you can solve this by additional filtering using `.where()` on the results? – Uwe - ObjectBox Oct 17 '22 at 07:25
  • Ok thanks for that. In Isar I can do something like the following, which does what I need `.anyOf([1, 3], (q, int e) => q.ordersElementEqualTo(e)) .and() .not() .ordersElementEqualTo(2)` – Fuxster Oct 18 '22 at 09:15

0 Answers0