Extra columns in bridging table
- Dominant language
- Kotlin
- Stars
- 9.3k
- Forks
- 798
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 26
Description
For many-to-many relations, the creation of bridging tables is often necessary. In some cases, these relations may require some extra data. To use the wiki example:
``` kotlin
// create film
val film = transaction {
StarWarsFilm.new {
name = "The Last Jedi"
sequelId = 8
director = "Rian Johnson"
}
}
//create actor
val actor = transaction {
Actor.new {
firstname = "Daisy"
lastname = "Ridley"
}
}
//add reference
transaction {
film.actors = SizedCollection(listOf(actor))
}
```
Suppose one were to add extra information to this relation, such as the role played, then the current solution would be to have a `Role`-like entity, referencing the film and actor, and containing the extra data. Now you have a problem referencing `Actor` using the `via` keyword. Wouldn't the following approach be preferable? Why is this not possible?
``` kotlin
// The StarWarsFilmActors table now contains a role field
object StarWarsFilmActors : Table() {
val starWarsFilm = reference("starWarsFilm", StarWarsFilms).primaryKey(0)
val actor = reference("actor", Actors).primaryKey(1)
val roleName = varchar("50")
}
```
``` kotlin
transaction {
film.actors.push(actor, {roleName = "Rey"})
}
```
Contributor guide
Assessment
This issue has not been assessed yet.