JetBrains / Exposed

Kotlin SQL Framework
http://jetbrains.github.io/Exposed/
Apache License 2.0
8.24k stars 686 forks source link

how do you reference in a DAO many-to-one #499

Closed lamba92 closed 5 years ago

lamba92 commented 5 years ago

Say you have 2 tables, CameraTable and SnapshotUriTable. Now for each camera you have many snapshotUris. You could follow the example and create an intermediary table, but what if you want to store the reference inside SnapshotUriTable with a column containing the id of the camera?

lamba92 commented 5 years ago

I guess it was easier then I thought!

class Camera(id: EntityID<Int>) : IntEntity(id) {
    var snapshotUris = CameraSnapshotUri.find { CamerasSnapshotUriTable.cameraId eq id }
}
Tapac commented 5 years ago

Did you try?

class Camera(id: EntityID<Int>) : IntEntity(id) {
    var snapshotUris = CameraSnapshotUri.referrersOn(CamerasSnapshotUriTable.cameraId)

This case described here closer to the end (look for Now if you wanted to get all the ratings for a film)

lamba92 commented 5 years ago

val snapshotUris by CameraSnapshotUrl referrersOn CamerasSnapshotUrlTable.cameraId did just fine! Thank you! I'd recomment to write it more explicitly int the wiki with a section titled many-to-one

Tapac commented 5 years ago

@lamba92 , wiki is open for a contibution. Feel free to update that section.