About how to INSERT records linked by different types of links.
1) FK-link and ObjectPtr link.
They are similar because here we have
- 2 Tables
- Second table have FIELD, which keep value of KEY from the first Table
- These links can establish 1:1 and 1:M links
To establish link between TWO records we just place VALUE of KEY into INSERT command for the second table.
This assumes that we have made INSERT into the first table BEFORE, and we have KEY value. To get the KEY value, the last_rec_id() function can be used for Valentina. Other DBs have similar function for PK/FK.
INSERT INTO T1( a1, a2, a3, ... ) VALUES ( va1, va2, va3, ... )
INSERT INTO T2( b1, b2, b3, T1_PTR ) VALUES ( vb1, vb2, vb3, last_rec_id() )
2) For BinaryLinks we DO NOT have any special field. BinaryLink is separate entity in database. BinaryLink can establish 1:1, 1:M and M:M links.
So we can compare BinaryLink of Valentina to additional third table in Relational model, to establish M:M links.
T12 ( T1_PTR, T2_PTR )
In relational model with ForeignKeys in such third table, you will need 3 INSERTs
INSERT INTO T1 ...
INSERT INTO T2 ...
INSERT INTO T12( T1_PTR, T2_PTR ) VALUES ( key1, key2 )
In similar way you will work with BinaryLink
INSERT INTO T1 ...
INSERT INTO T2 ...
LINK RECORD(key1) OF tbl1 WITH RECORD(key2) OF tbl2;
3) Important to notice, that in real life, you are not forced to have such 3 INSERTs one by one.
Yes this can happens, but on the other hand exists scenarios, when you have added today record into T1, tomorrow record into T2 and only week later you will need LINK them together.
So it is up to you how you design your code in your project.
* May be as Stored Procedures with few INSERTs following one another,
* may be separate functions that do 3 independent INSERTs
* may be else ...