1

I have 2 classes set up with these relations, with Faults only having 1 equipment, and equipment having many faults.

@Entity()
class Equipment {
  int? id;
  String adminNumber;
...

  @Backlink()
  final faults = ToMany<Fault>();
...
}

@Entity()
class Fault {
  /// Let objectbox handle ID assigning
  int? id;
  String uuid;
...

  final equipment = ToOne<Equipment>();
...
}

I'm attempting to utilize the backlink to find all equipment that has a connection to a fault, (as equipment can be created without a fault).

But I can't seem to access the faults property of the equipment

final testQuery = _localDbBaseService.faultsBox.query()
  ..backlink(Equipment_.faults, Equipment_.faults.notNull());
final test = testQuery.build().find();

return test;

"The getter 'faults' isn't defined for the type 'Equipment_'."

I'm pretty sure I have the query backward, but I'm just attempting to figure out how to correctly use backlink. I know I could walk through this forward by querying all faults and then querying all equipment and filtering them like that, but I feel as if backlink should function this way....or am I completely misunderstanding its intention? I can't seem to find many examples relating to Backlinks, especially with in Dart

1 Answer 1

3

Oh man, the rubber ducky method helps again, I feel like an idiot. Anyway, for anyone else that stumbles upon this working with backlinks in flutter, you do indeed query the "parent" object

final builder = _localDbBaseService.equipmentBox
    .query();
builder.backlink(Fault_.equipment, Fault_.equipment.notNull());
final query = builder.build();
final items = query.find();

return items;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.