Hi, I have struggled to get to where I'm at, and juging by the number of same problems/questions I saw on the forum, i thought I'd share my recently acquire knowledge with a small recap of how I did things.
The main points in the scenery are :
- I have a Database Table : 'ligne_ecriture'
- I want to perform CRUD operations from a table view, but I did not rely on changeset. (yellow frame, edit and delete actions on the right)
- I want to be able to cancel changes any time, so the changes happen in one step at the end. (button down right)
The table takes the data from a Variable 'currentLigneList'
As it happens, I also have a foreign key in this table, (this is beside the scope, but there was some hassle)
Now for the operations :
I can perform CRUD operations on a set of records, which make things tricky :
Creating a whole set :
I use the form under the table to populate the Variable array, with 'setIn' for the whole record :
When done creating the lines, I validate, and I make a bulk insert with my Variable array :
(There is a minor trick, (not included) because I have also to populate the foreign keys)
Modifying a set :
This involves
- creating new lines (as above)
- modifying existing lines (again with 'setIn', but individual values)
- deleting line (with the use of 'splice' on the Variable array via a temp object)
When done modifying the set, I validate. The only valid option is to first delete all the existing set (in my case, i'ts identified with the foreign key),
and reinserting the new set (as above in creation)
Deleting a set :
In this case, I don't need to load the table view, so it's rather straightforward
The whole point of this is I can cancel creation / modification any time without having modified the database.
Also, the embedded FK gave me a LOT of trouble since nothing worked (array.forEach(), object.assign(), ...). I had to do a for loop with setIn, which is cumbersome.
Hope this helps.