via
infix fun <TID : Any, Target : Entity<TID>> EntityClass<TID, Target>.via(table: Table): InnerTableLink<ID, Entity<ID>, TID, Target>
Declares a many-to-many relationship held by the intermediate table, whose references to this entity's table and to the target's table are inferred from its foreign keys:
class Film(id: EntityID<Int>) : IntEntity(id) {
var actors by Actor via FilmActors
companion object : IntEntityClass<Film>(Films)
}
film.actors = SizedCollection(actor1, actor2) // replaces the links
val cast = film.actors.toList() // the property is a Flow, so collect itContent copied to clipboard
fun <TID : Any, Target : Entity<TID>> EntityClass<TID, Target>.via(sourceColumn: Column<EntityID<ID>>, targetColumn: Column<EntityID<TID>>): InnerTableLink<ID, Entity<ID>, TID, Target>
Declares a many-to-many relationship, naming sourceColumn and targetColumn explicitly. Use this overload when the intermediate table holds more than one reference to either side, which leaves nothing to infer:
class Node(id: EntityID<Int>) : IntEntity(id) {
var parents by Node.via(NodeToNodes.child, NodeToNodes.parent)
var children by Node.via(NodeToNodes.parent, NodeToNodes.child)
companion object : IntEntityClass<Node>(Nodes)
}Content copied to clipboard