Kotlin Exposed - How to find a DAO using a Join


#1

In the sample provided with Kotlin Exposed, how can I find the City DAO if I have the name of the User with whom the city is associated?

(In other words, while the examples show joins on DSLs using innerjoin, I could not load a DAO for one table, by joining its table with another and specifying the where clause on the values of the other table).


#2

Not sure that I fully understand, but If you want to get City for User founded by name then you can try (work for SampleDao.kt):

val city = User.find { Users.name eq "Name" }.singleOrNull()?.city

Another way is to use EntityClass.wrapRows() function around query with Cities table:

val cities = City.wrapRows(
     Users.innerJoin(Cities).select { Users.name eq "Name" }
).toList()