0

The ObjectBox docs and my own empirical research have shown the @Backlink annotation should always be placed on the ToMany side of a One to Many relationship, but it is unclear to me if it matters which side of a Many to Many relationship the @Backlink annotation should be placed on. Is there any benefit to having it on the more/less frequently accessed side of the relationship?

ubiquibacon
  • 10,451
  • 28
  • 109
  • 179

1 Answers1

0

A ToMany annotated with @Backlink does not actually exist in the database. It is kind of dynamically resolved based on the relation it links back to, be it a ToOne or ToMany relation.

I would choose the "base" relation based on which is the actual relation that should be stored (and modified).

Uwe - ObjectBox
  • 1,012
  • 1
  • 7
  • 11
  • Ah I didn't realize that. Things I had read indicated that the `@Backlink` annotation created additional indexes in the DB to support it. Would you recommend using `@Backlink` anytime a backlink is needed, or to avoid it unless some specific criteria is met? If the latter, what is that criteria? – ubiquibacon Feb 20 '23 at 18:43
  • I can't really think of a reason to avoid it. Note that it is not even required to add a "backlink" relation, you can also write a query with a backlink condition when needed: https://docs.objectbox.io/queries#add-query-conditions-for-related-entities-links – Uwe - ObjectBox Feb 21 '23 at 07:02