https://kotlinlang.org logo
#exposed
Title
# exposed
f

frellan

06/22/2018, 9:43 PM
Hello guys! I am planning on moving to this library for persistence, planning to use the DSL since I want more control of my sqls. Just a general question really, how do one handle nested relations with a dsl approach? One may want to have relations on the domain model but don’t load them all the time, so they would be null, so you would end up with a lot of stuff that is null, which is not nice. How do you guys do this? Remove the relations from the domain model and just keep the relations in the database, i.e dont do
entity.otherEntites
but rather
DB.getOtherEntetiesFor(entity)
or similar. How do you do this, need tips 🙂
t

tapac

06/25/2018, 9:38 AM
I guess that you can use something like:
Copy code
class YourEntity {
   val otherEntities get() = DB.getOtherEntetiesFor(this)
}
f

frellan

06/25/2018, 1:32 PM
Yeah but then I do what a lazy ORM does and I’m back to not knowing when I talk to the DB. Plus I mix model and DB logic which is not very nice. But I guess there is not so many other ways to do it. How do you do this traditionally?
t

tapac

06/25/2018, 11:29 PM
You asked about a DSL way, but if you work with Exposed DAO entities then you just have to use proper mapping. https://github.com/JetBrains/Exposed/wiki/DAO#simple-reference
4 Views