MJoin editing

MJoin editing

classic2020classic2020 Posts: 4Questions: 2Answers: 0
edited August 2020 in Free community support

Good day, is there a possibility to do one-to-many joins with a feature to text edit the value on the joined table? As far as I know it is only allowed to have checkbox for now.
According to ->
https://datatables.net/forums/discussion/27282/best-way-of-editing-one-to-many-table

I tried to use several left joins.. the data is shown correctly but if i edit a value it changes for all entries inside the joined table for the referenced row in original table.

Thank you very much in advance!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin
    Answer ✓

    Currently no, it isn’t possible in Editor I’m afraid. The closest is to use parent / child editing as described in this blog post.

    Allan

  • classic2020classic2020 Posts: 4Questions: 2Answers: 0

    Thank you Allan!
    Is it possible then to create a record on one table. get its ID and then create record on the other table so it could store the previously obtained ID?
    It should be the same as UPLOAD file feature works but I cant get it done for normal relational DB. Thank you advance!

  • rf1234rf1234 Posts: 2,949Questions: 87Answers: 416
    edited August 2020

    That can easily done with the server events. Here is an example from my own coding. Writing the log:

    ->on( 'postCreate', function ( $editor, $id, $values, $row ) {            
        logChange( $editor->db(), 'create', $id, $row, 'cashflow' );
    } )
    ->on( 'postEdit', function ( $editor, $id, $values, $row ) {
        logChange( $editor->db(), 'edit', $id, $row, 'cashflow' );
    } )
    ->on( 'postRemove', function ( $editor, $id, $values ) {
        logChange( $editor->db(), 'delete', $id, $values, 'cashflow' );
    } )
    ->process($_POST)
    ->json();
    

    The function called:

    function logChange ( $db, $action, $id, $values, $tableChanged ) {
        $db->insert( 'log', array(
            'user_id'       => $_SESSION['id'],
            'table'         => $tableChanged,
            'action'        => $action,
            'values'        => json_encode( $values ),
            'changed_id'    => $id
        ) );
    }
    
    

    Here is another one using Editor's raw() method which is more flexible:

    ->on( 'postRemove', function ( $editor, $id, $values ) {
        logChange( $editor->db(), 'delete', $id, $values, 'user' );
        //delete potential private event notifications for the deleted user
        $editor->db()->raw()
           ->bind( ':user_id', $values["user"]["id"] ) 
           ->exec( 'UPDATE ctr_event    
                       SET msg_private = 0
                     WHERE updater_id = :user_id' );
    } )
    ->process($_POST)
    ->json();
    
This discussion has been closed.