nested CDTs and Writing Data to Database

Hi, I have multiple CDTs that have various relationships set up. What I am not clear on is how the ids that would enable the records to relate appropriately are passed from the parent CDT to the child CDT? For example, if an app allows you to create a customer and that customer has many phone numbers, I would have a parent CDT with a one to many relationship with a phone number CDT. When a user enters information into the form, how should the customer key flow into the phone number CDT to allow the relationship to work? Is it expected that this occurs automatically, or would you just program for this where a script task runs in the process model to add the applicable customer id into the applicable phone number rows in the child CDT? (i.e. script task using: repeat(count(pv!childCDT),pv!parentCDT.id) 

 

THANKS!

  Discussion posts and replies are publicly visible

Parents
  •  I may not have explained my initial question well but essentially the key linking the child CDT to my parent CDT was not populating as I expected it to. I went away from this method after researching it more extensively. I found what  found, which was that it was not as easy/clean of a methodology as I initially thought it would be. I did end up just using the process model and script task functionality to grab the parent key and put it in the child CDT. This resulted in a much cleaner process and so far has enabled me to do everything I need. So for anyone looking to do something similar, it seems the best method is to just us the process model to grab the parent keys and put them into the child CDTs.

  • Lets say you are persisting to the `parent` entity, which is a parent of `nest`with the following data:

    ```
    parent = {
    "foo" : "bar",
    "nest": {
    "hello": "world"
    }
    }
    ```

    If you just put this data into a write to data store entity, and you have CascadeType.ALL, you should have primary keys for both, as well as a matching foreign key in the foo data

    so it will look like

    parent:
    id: 1
    nest_id: 1
    foo: bar

    nest
    id 1
    hello: world
Reply Children
No Data