mars8
mars8

Reputation: 1246

Kotlin Exposed - automatically create record in child table when new record is added to parent table

I have ParentTable and ChildTable as table entites. When a record is inserted into ParentTable i want it to automatically create a record in ChildTable. The child table has two columns, colA is the row id of the parent table and colB is some default value.

Is there any way to automatically do this in Kotlin Exposed using DAO and cascade function onUpdate?

Upvotes: 1

Views: 341

Answers (1)

Last Noob Ninja
Last Noob Ninja

Reputation: 81

It would be good if you provide more information. But you can use DAO lifecycle hooks in your parent entity class. something like below:

EntityHook.subscribe {
   if (it.changeType == EntityChangeType.Created) {
      // insert in child table
   }
}

Upvotes: 1

Related Questions