Relations
KraftAdmin automatically detects JPA relationships and renders them as relational selectors.
Supported relationship types include:
- One-to-One
- Many-to-One
- One-to-Many
- Many-to-Many
Automatic Detection
@ManyToOne
var department: Department? = null No annotation is required.
KraftAdmin automatically renders a relation selector.
Explicit Relation
@KraftAdminField(
inputType = FormInputType.RELATION
)
@ManyToOne
var department: Department? = null Multiple Relations
Collections automatically become multi-selection relation components.
@ManyToMany
var roles: MutableSet<Role> = mutableSetOf() Equivalent explicit configuration:
@KraftAdminField(
inputType = FormInputType.MULTI_RELATION
)
@ManyToMany
var roles: MutableSet<Role> = mutableSetOf() Display Fields
By default KraftAdmin attempts to determine the most meaningful property to display.
You can explicitly define it.
@KraftAdminField(
displayField = true
)
var name: String = "" The property marked with displayField becomes the label shown inside relationship selectors.
Example:
Departments
Finance
Engineering
Marketing instead of
Department #17
Department #42
Department #53 Lazy Loading
Relationships are loaded only when required by the interface.
Large datasets remain responsive through pagination and lazy loading.
Searching
Relation fields provide searchable lookups.
Administrators can quickly locate related records without scrolling through long lists.
Best Practices
- Always define a display field.
- Use concise entity names.
- Avoid exposing technical identifiers.
- Prefer lazy loading for large datasets.