Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Suggested Answer
Replies
15 replies
Answers
4 answers
Subscribers
14 subscribers
Views
4560 views
Users
0 members are here
foreign key
table
write to data store
relation
db
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
Data and Records
How to add the data to DB within a 2 tables 1-N relation?
cedric01
Certified Senior Developer
over 3 years ago
Hi,
When I have to add data within a 1-1 relation between 2 tables, I call the "Write to data store entity" Smart Service to add the new record in the parent table and then, from this component output, I retrieve the generated key Id, to set the Foreign Key in the child table.
How would you do for a 1-N relation?
Is there any way to add the data in the 2 tables (1 record in the parent table, and N records in the child table) in a simple way without doing any loop to set the FK ?
What is the better way to do it please ?
Discussion posts and replies are publicly visible
Top Replies
Dave Lewis
over 3 years ago
in reply to
cedric01
+1
suggested
Certified Lead Developer
Two consecutive write to datastore nodes would be much safer. It ensures that you won't even start writing contacts with dangling pointers until the object of their pointer is fully built. This is also…
Mike Schmitt
over 3 years ago
in reply to
cedric01
+1
suggested
Certified Lead Developer
This doesn't seem so bad, to me. It's the sort of thing that only needs to be done the "first time", as it were. If you were in some crunch to reduce the total number of nodes to the absolute minimum,…
Chris
over 3 years ago
in reply to
cedric01
+1
While there are no issues with a!forEach() for this approach, you can also accomplish this with the makerange() function, save into the child FK's directly, if you are looking for different options. The…