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

Volodya Gurdin

10/09/2020, 7:54 AM
Hi guys, is there any particular reason for entity to be inside transaction block if i want to know id value in reference column? For example
entity.parent?.id?.value
code will throw
No transaction in context
although entity table has parent_id column and it should know parent id value when you fetched it, so no additional queries needed to DB. And exposed seems to know that, cause if i put this code under transaction block - parent id will be returned without any additional queries
t

tapac

10/13/2020, 8:45 AM
All references keept in EntityCache bound to transaction. When you use
entity.parent
the Parent instance is looked up from cache and it is absent there then Exposed will load it. You can define
parentId
field on the Entity and then it will just return the field value and will not require the transaction.
2 Views