Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra columns in bridging table #667

Open
thedjdoorn opened this issue Oct 28, 2019 · 0 comments · May be fixed by #2204
Open

Extra columns in bridging table #667

thedjdoorn opened this issue Oct 28, 2019 · 0 comments · May be fixed by #2204
Assignees

Comments

@thedjdoorn
Copy link

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:

// 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?

// 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")
}
transaction {
    film.actors.push(actor, {roleName = "Rey"})
}
@bog-walk bog-walk self-assigned this Jul 29, 2024
@bog-walk bog-walk linked a pull request Aug 16, 2024 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants