Richard Romanowski
03/14/2022, 3:40 PMobject UserRatings: IntIdTable() {
val value = long("value")
val film = reference("film", StarWarsFilms)
val user = reference("user", Users)
}
class UserRating(id: EntityID<Int>): IntEntity(id) {
companion object : IntEntityClass<UserRating>(UserRatings)
var value by UserRatings.value
var film by StarWarsFilm referencedOn UserRatings.film // use referencedOn for normal references
var user by User referencedOn UserRatings.user
}
If I have the ID of a film how can I create a new rating with the DAO api?
Example:
val filmId: UUID = getFilmId()
val rating = UserRating.new {
// what goes here to set film?
}
Calvin
03/14/2022, 3:42 PMfilm = FilmEntity[filmId]
or maybe
film = StarWarsFilm[filmId]
Richard Romanowski
03/14/2022, 3:47 PMCalvin
03/14/2022, 3:50 PMval rating = UserRating.new {
film = StarWarsFilm.get(filmId)
}
hfhbd
03/14/2022, 3:51 PMvar filmID by UserRatings.film
new {
this.filmID = filmId
}
Richard Romanowski
03/14/2022, 5:14 PMreferencedOn
?hfhbd
03/14/2022, 5:16 PMReferencedOn
reads the whole row from the referenced tableRichard Romanowski
03/14/2022, 5:16 PMreferencedOn
I don't see how to set that field when I'm creating a new record when I have the id of the reference I want to set without making an extra call to the dbhfhbd
03/14/2022, 5:18 PMnew { this.film = filmDao }
If you already have the id, use new { this.filmID = filmId }
.Richard Romanowski
03/14/2022, 5:19 PMhfhbd
03/14/2022, 5:20 PMvar filmID by UserRatings.film
class UserRating(id: EntityID<Int>): IntEntity(id) {
companion object : IntEntityClass<UserRating>(UserRatings)
var value by UserRatings.value
var film by StarWarsFilm referencedOn UserRatings.film // use referencedOn for normal references
var filmID by UserRatings.film
var user by User referencedOn UserRatings.user
}
val filmId: UUID = getFilmId()
val rating = UserRating.new {
filmID = filmId
}
Richard Romanowski
03/14/2022, 5:21 PM