How to write data to multiple tables with datatables editor?

How to write data to multiple tables with datatables editor?

T.I PeccinT.I Peccin Posts: 3Questions: 0Answers: 0

I have 5 databases in which I want them to communicate with each other, that is, for one to be dependent on the other. In my case, I need the ID of table1 to be table2.id_table1 and so on, within my scenario. I have a table that registers the uploads in which it is already working, however, it does not save the other data from the other tables. Does the Datatables Editor support this type of operation? If so, how could I perform this process?

Replies

  • rf1234rf1234 Posts: 2,991Questions: 87Answers: 421

    Do these databases have identical data? Or are they different? They have a foreign key relationship as you write.

    Here is something that could be relevant for you:
    https://datatables.net/forums/discussion/73872

    If a join doesn't work for you you can also make your own INSERTs, UPDATEs and DELETEs using different db handlers to connect to the other databases.

    You could use "writeCreate", "writeEdit" and "postRemove"
    https://editor.datatables.net/manual/php/events
    and execute your own proprietary SQL.

  • T.I PeccinT.I Peccin Posts: 3Questions: 0Answers: 0

    Yes, these tables have foreign keys, where for example table1.id is an attribute of table2. I am using the Oracle database and for this I created a trigger to add the id to the tables, something similar to the file table that appears in the DataTables documentation.
    Below is an example of my code.
    https://github.com/PeccinCodes/Compartilhamento/blob/main/datatables.editor.php
    Is the code syntax correct? Or is it not possible to perform this operation?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    When you say "databases", do you actually mean tables here? The PHP code suggests you have a single database connection but five different tables in that database.

    In principle, yes, I think it should work, if you submit the primary key of the joined table records. You have ->debug(true) already - perhaps you could so me the JSON return from an edit command?

    That said, I am steering Editor away from 1:1 editing over multiple tables. I think conceptually it is a lot easier to work with nested editing and there are a lot less footguns!

    Allan

  • T.I PeccinT.I Peccin Posts: 3Questions: 0Answers: 0

    Exactly, I only have one database connection but several tables, but when I go to create a new record it only saves the data from the files in the file table that has the following name PCN_SIG_QUALIDADE_FILE. in my json it returns blank. I don't understand what the problem with the code is or how to solve it.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Unfortunately you didn't include the information I asked for in my reply. Could you add that please? I'd also be interested in seeing the parameters server to the server on edit.

    However, as I said, I would strongly encourage you to not edit multiple tables this way - for example, say you change which row the primary table links to and edit a field for the linked table. It could be ambiguous as to which row should get edited in the linked table (depending on how it is presented to the end user).

    Allan

Sign In or Register to comment.