Link

@Target(allowedTargets = [AnnotationTarget.PROPERTY])
annotation class Link(val to: KClass<*>, val name: String)

Creates a one-way link with the to class on the name field, meaning that upon the removal of an entity of the annotated class, all entities of the to class with a name field value equal to this annotated field will also be removed.

data class User(@Identity @Link(to = UserMessage::class, name = "userId") val id: Long)
data class UserMessage(@Identity val id: Long, val userId: Long)

suspend fun example(cache: DataCache) {
val user = User(0)
val willBeRemoved = UserMessage(15, user.id) //userId == user.id, so upon removal of user this value will be removed
val wontBeRemoved = UserMessage(16, 20)

cache.put(user)
cache.putAll(willBeRemoved, wontBeRemoved)
cache.find<User> { User::id eq user.id }.remove()
val shouldBeRemoved = cache.find<UserMessage> { UserMessage::id eq willBeRemoved.id }.singleOrNull()

assert(shouldBeRemoved == null)
}

Properties

Link copied to clipboard
Link copied to clipboard
val to: KClass<*>