# exposed


07/08/2018, 5:46 PM
Hi! I'm a bit new to ORM and DB connection in app. I've switched from DAO to DSL way because of better separation between data and code (multitier architecture). Question - what would you recommend to access values from referenced columns (like in DAO way)? I'm talking about using
data class
in higher tiers. Only possible way I could come up with is to create
for every 1:N relationship, which might be very monstrous in the end. How do you usually deal with that? Thanks for the reply in advance!


07/11/2018, 10:42 AM
Why 1:N is a
not a
? You may end up like this :
Copy code
object ParentTable : IntIdTable()
    object ChildTable : IntIdTable() {
        val parentId = reference("parentId", ParentTable)
    data class Parent(val id: Int) {
        val children get() = { ChildTable.parentId eq id }.map { Child.wrap(it) }
        companion object {
            fun wrap(rs: ResultRow) : Parent = Parent(rs[].value)
    data class Child(val id: Int, val parentId: Int) {
        val parent get() = { eq parentId }.singleOrNull()?.let { Parent.wrap(it) }
        companion object {
            fun wrap(rs: ResultRow) : Child = Child(rs[].value, rs[ChildTable.parentId].value)
It might be not very clear, sorry. I mostly use Exposed DAO for entities.