Alice
11/26/2018, 4:05 PMclass User(id: EntityID<Long>) : LongEntity(id) {
var images by Image via UserImages
companion object : LongEntityClass<User>(Users)
}
My image simplified is like
class Image(id: EntityID<Long>) : LongEntity(id) {
val user by User referencedOn Images.user
companion object : LongEntityClass<Image>(Images)
}
And my tables are as follows
object Images : LongIdTable() {
val user = reference("user", Users)
}
object Users : LongIdTable() {
// Do I need to do something to establish a relationship to images here?
}
object UserImages : Table() {
val user = reference("user", Users).primaryKey(0)
val image = reference("image", Images).primaryKey(1)
}
I've been following the tutorial on the wiki, and I was fine with everything I think until I started trying to establish this relationship. I hope this isn't too much of a noob question, I just decided to try Kotlin yesterday after people scala-shaming me for months 😜.tapac
11/26/2018, 4:16 PMAlice
11/26/2018, 4:19 PMtapac
11/26/2018, 4:23 PMUserImages
table.
use val images by Image.referrersOn(Images.user)
Alice
11/26/2018, 4:26 PMval user = reference("user", Users)
is what I'm referencingtapac
11/26/2018, 4:31 PMAlice
11/26/2018, 4:32 PMtransaction {
film.actors = SizedCollection(listOf(actor))
}
But doing so in my case is a problem, since changing images to val
causes an error.
I'd prefer to keep as much code immutable as possible, so how do I work around this?tapac
11/26/2018, 4:44 PMval
to var
but I prefere to set user to a image in a creation time, like:
val newImage = Image.new {
...
this.user = ownerOfImage
}
Alice
11/26/2018, 4:45 PMtapac
11/26/2018, 4:48 PMuser.images
Exposed will load all Image
instances where user
column equals to user.id
value.
So when you create new Image and fill user
field you automatically "update" result which will be returned by next user.images
call.Alice
11/26/2018, 4:48 PM