← Back to Stormify Documentation

attach

fun <T : StormifyAware> attach(target: T): T

Attaches this Stormify instance to target so the target can use it for database operations without receiving it as an explicit parameter.

Works for any StormifyAware — StormifyEntity subclasses (entities, AutoTable) and PagedList instances. Returns target for fluent chaining.

// Manual stub — user knows the ID, lets Stormify lazy-load the rest
val user = stormify.attach(User().apply { id = 42 })
println(user.name) // triggers SELECT via the attached instance

// Paged list — attach before use (or rely on Stormify.defaultInstance)
val list = stormify.attach(PagedList<Company>())
list.addFacet("name")