Relation

@Target(allowedTargets = [AnnotationTarget.PROPERTY])
annotation class Relation(val cascade: Boolean = false)

Marks a FK property as a relationship to another @DbEntity.

@DbEntity(tableName = "tasks")
data class Task(
@PrimaryKey(autoGenerate = true) val id: Long = 0,
val title: String,
@Relation val projectId: Long = 0 // FK to Project
)

The processor infers the parent entity name from the property name by stripping the trailing Id suffix (e.g. projectId → Project).

Generated methods on TaskRepository:

  • findByProject(projectId: Long): List<Task>

  • observeByProject(projectId: Long): Flow<List<Task>>

  • deleteByProject(projectId: Long)

Parameters

cascade

When true, a KDoc hint is added to deleteByProject noting that callers should invoke it before deleting the parent.

Properties

Link copied to clipboard
val cascade: Boolean = false