Navigating (updatable) records
jOOQ exposes several navigation methods that can be used for attached (updatable) records only (TableRecord
and UpdatableRecord
). To use these methods, please consider the following note.
Important Note
While these methods are very convenient/appealing, they are also a big N+1 risk. UpdatableRecord
is great for CRUD, but if you aren't using CRUD, then you shouldn't use UpdatableRecord
. It's better to project only the columns you need and try to use joins or other SQL utilities to fetch data from multiple tables.
These methods navigate based on the foreign key references. For instance, with an attached DepartmentRecord
, we can navigate its parent (OFFICE
) via fetchParent(ForeignKey<R, O> key)
, as shown in the following example:
public OfficeRecord fetchOfficeOfDepartment( DepartmentRecord dr) { return dr.fetchParent(Keys.DEPARTMENT_OFFICE_FK); // or, Keys...