Jooq foreign key relation

20 views Asked by At

How does work foreign key relations in JOOQ? Let me clarify a bit:

  1. Main table - A
  2. Foreign table - B

In code you can call a method to access main table using foreign table B.a().

Let's say I am calling

dsl.select(B.a().ID).from(B).fetchInto(String.class);

Does it use left join inside the box of JOOQ?

1

There are 1 answers

0
Lukas Eder On BEST ANSWER

Implicit path joins default to using a LEFT JOIN if your foreign key is nullable, and INNER JOIN if your foreign key is non-nullable.

The default type of join that is generated is:

INNER JOIN for to-one path segments with non-nullable parent LEFT JOIN for to-one path segments with nullable parent

But you can override this behaviour if you always prefer a LEFT JOIN, for example:

Settings settings = new Settings()
    .withRenderImplicitJoinType(RenderImplicitJoinType.LEFT_JOIN);