Berkay Özkan
10/06/2022, 1:12 PMobject Users: IntIdTable() {
val name = varchar("name", 50)
}
class User(id: EntityID<Int>): IntEntity(id) {
companion object : IntEntityClass<User>(Users)
var name by Users.name
}
object UserRatings: IntIdTable() {
val value = long("value")
val user = reference("user", Users)
}
class UserRating(id: EntityID<Int>): IntEntity(id) {
companion object : IntEntityClass<UserRating>(UserRatings)
var value by UserRatings.value
var user by User referencedOn UserRatings.user
}
When i want to create new UserRating i get id of user, and value (5 star etc)
val movie = UserRating.new {
value = 5
user = ? // This expects an User object
}
How can I use only id when creating UserRating? Or do i have to get User from db with selectById? (Isn’t it unneccesarry get operation?)Maksym
06/02/2024, 9:28 PMBerkay Özkan
06/02/2024, 11:27 PMUserRating.insertAndGetId {
it[value] = 5
it[user] = EntityID(userId, Users)
}
We do solution something like this using DSL not sure if this work for DAO