Joined Tables Not Displaying Properly

Joined Tables Not Displaying Properly

gforstergforster Posts: 40Questions: 19Answers: 1

I have one table with an Mjoin for a "link table" (Joining the "VOLUMES" and "APPS" mysql tables) displaying one column. Another separate table with the same Mjoin, but displaying the other column.

When I edit the field, I expect the same information to show up both places, but it doesn't. Any idea what could be causing this to happen? I shouldn't have to edit in two places.

The two joins:

    // Apps
    ->join(
             Mjoin::inst( 'APPS' )
                 ->link( 'VOLUMES.id', 'VOL_APPS.volume_id' )
                 ->link( 'APPS.id', 'VOL_APPS.app_id' )
                 ->fields(
                     Field::inst( 'id' )
                         ->options( Options::inst()
                             ->table( 'APPS' )
                             ->value( 'id' )
                             ->label( 'name' )
                         ),  
                     Field::inst( 'name' )
                 )   
         )
    // Volumes
     ->join(             
             Mjoin::inst( 'VOLUMES' ) 
                 ->link( 'VOLUMES.id', 'VOL_APPS.volume_id' )
                 ->link( 'APPS.id', 'VOL_APPS.app_id' )
                 ->fields(
                     Field::inst( 'id' )
                         ->options( Options::inst()
                             ->table( 'VOLUMES' )
                             ->value( 'id' )
                             ->label( 'name' )
                         ),
                     Field::inst( 'name' )
                 )
         )

And how they're called in Editor:

// Volumes
     fields: [ {
                     label: "Volume:",
                     name: "VOLUMES.name",
                     type: "select",
                     placeholder: "Select the Volume Name"
                 }, {
                     label: "Applications:",
                     name: "APPS[].id",
                     type: "checkbox"
                 }

// Apps
    fields: [ {
                     label: "Name:",
                     name: "APPS.name"
                 }, {
                     label: "Associated Volumes:",
                     name: "VOLUMES[].id",
                     type: "checkbox"
                 }
`
And the display in the Datatable:
`
// Volumes
 columns: [
                 { data: "VOLUMES.name"},
                 { data: "APPS", render:"[, ].name"}

// Apps
 columns: [
                 { data: "APPS.name" },
                 { data: "VOLUMES", render:"[, ].name"}

Answers

  • gforstergforster Posts: 40Questions: 19Answers: 1

    Debug for Volumes table:

    https://debug.datatables.net/urokur

    Debug for Apps table:

    https://debug.datatables.net/afefod

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

    I'm not quite clear on the table structure. What is the parent table for these two Mjoins?

    Allan

  • gforstergforster Posts: 40Questions: 19Answers: 1

    Volumes_Apps is a link table that contains volume_id column (which links to Volumes.id) and app_id column (which links to Apps.id).

    I have two different Datatables (one to show details about Volumes, another to show details about Apps). In the Volumes view, it should show a column with an array of Apps (using that Volumes_Apps linking table) and in Apps view, it should show a column with an array of Volumes (using the same linking table).

    When I update via Editor in one view (Volumes or Apps), I expect to see the change reflected in both places, since it is making the change to the DB on the same table, but I am only seeing the change on the table I edit.

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

    Ah I see what you mean - Editor will only reflect the change on the table that is being modified until you refresh the page. This is because it doesn't have any listeners or knowledge of the link between those two tables (that might happen in future though!).

    So at the moment what you would need to do is call ajax.reload() on the table which what not the one being edited - e.g.:

    editor1.on( 'submitComplete', function () {
      table2.ajax.reload( null, false ); // hold the paging in place
    } );
    
    editor2.on( 'submitComplete', function () {
      table1.ajax.reload( null, false );
    } );
    

    Allan

This discussion has been closed.