Join - Cross Fields Capabilities

Join - Cross Fields Capabilities

BROB201BROB201 Posts: 28Questions: 4Answers: 0
edited October 2013 in Editor
Hi,

I just bought the editor and I love it.

I was playing around with the join example and I have a question about it:

If I have a simple join, let's say "Table_A inner join Table_B on ID" and I don't want any edit/create/delete to have any effects on Table_B, I use [code] ->set( false ) [/code] in the join class, simple.

So let's say I have displayed in my table:
Table_A.ID, Table_B.ID, Table_B.name


Now, when I want to edit or create a row, I get a "select" (drop-down menu, again like in the join example) populated by values in Table_B.name in my edit window. If I select any values in this menu and "submit" my entry, Table_B will not be updated (which is expected) but neither will the corresponding value in Table_A (through the join, Table_A.ID).

My question: is the only way to accomplish this through server-side code like it is suggested below?

https://datatables.net/forums/discussion/13933/update-a-field-based-on-the-value-of-another/p1

Replies

  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    Are you able to show me the page you are working on and the PHP used in the script? It should be that the set(false) will only effect the Join it is applied to, so it you are using another join for table A it should work as expected.

    Thanks,
    Allan
  • BROB201BROB201 Posts: 28Questions: 4Answers: 0
    Well, I had the time to integrate it to one of my projects, so I will send you a link and here is the PHP:

    [code]
    $editor = Editor::inst( $db, 'version_test', 'id_version' )
    ->fields(
    Field::inst( 'id_version' ),
    Field::inst( 'version' ),
    Field::inst( 'fkid_device_type' ),
    Field::inst( 'fkid_compliance' ),
    Field::inst( 'asofdate' ),
    Field::inst( 'filename' ),
    Field::inst( 'solution' )
    )
    ->join(
    Join::inst( 'device', 'object' )
    ->join( 'fkid_device_type', 'id_device_type' )
    ->set( false )
    ->field(
    Field::inst( 'id_device_type' ),
    Field::inst( 'device_type' ),
    Field::inst( 'fkid_vendor' ),
    Field::inst( 'hardware_id' )
    ),
    Join::inst( 'compliance', 'object' )
    ->join( 'fkid_compliance', 'id_compliance' )
    ->set( false )
    ->field(
    Field::inst( 'id_compliance' ),
    Field::inst( 'compliance_status' )
    )
    );


    // The "process" method will handle data get, create, edit and delete
    // requests from the client
    $out = $editor
    ->process($_POST)
    ->data();


    // When there is no 'action' parameter we are getting data, and in this
    // case we want to send extra data back to the client, with the options
    // for the 'department' select list and 'access' radio boxes
    if ( !isset($_POST['action']) ) {
    // Get department details
    $out['compliance'] = $db
    ->select( 'compliance', 'id_compliance as value, compliance_status as label' )
    ->fetchAll();
    }

    // Send it back to the client
    echo json_encode( $out );
    [/code]

    So basically, in the edit window, if I change the value in the drop down for compliance (compliance.compliance_status), I would like the corresponding value in the main table (version.fkid_compliance) to be updated but I don't want to change the compliance table at all. Does it make sense?
This discussion has been closed.