is mJoin only reading

is mJoin only reading

INTONEINTONE Posts: 153Questions: 58Answers: 6
edited July 2016 in Editor

I once used the join classes in php to read and write from a link table. Now when i upgrade and use the mJoin i only seem to be able to read.

Here is my code:

$data->join(
        Mjoin::inst( 'contacts' )
            ->link( 'cases.caseID', 'caseClient.caseID' )
            ->link( 'contacts.contactID', 'caseClient.contactID' )
            ->fields(
                Field::inst( 'contactID' )
                    ->options( function () use ( $db ) {
                        $userList = $db->sql( "SELECT concat(contactLastName,', ',contactFirstName,' ',contactMiddleName) as name, contactID as id FROM contacts WHERE contactType != 'Company' order by contactLastName asc, contactFirstName asc" );
                        $out = array(array('label'=>'Select...','value'=>''));
                     
                        while ( $row = $userList->fetch() ) {
                            $out[] = array(
                                "label" => $row['name'],
                                "value" => $row['id']
                            );
                        }
                     
                        return $out;
                    } ),
                   Field::inst( 'contactID' )->validator( 'Validate::notEmpty' )
            )
    )

I am getting the data from the contacts table but when I insert and update no values are written to caseClient. what am I doing wrong.

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,473 Site admin

    That looks like it should work. Could you link to the page showing the issue please.

    Allan

  • INTONEINTONE Posts: 153Questions: 58Answers: 6

    This is on a local server but maybe the full server code will help:

    $data = Editor::inst( $db, 'cases', 'caseID' )
        ->fields(
            
            Field::inst( 'cases.caseID' )->set(false),
            Field::inst( 'cases.caseName' )->validator( 'Validate::required' ),
            Field::inst( 'cases.caseType' )->validator( 'Validate::required' ),
            Field::inst( 'cases.companyBranchID' )->options( 'companyBranches', 'companyBranchID', 'name' ),
            Field::inst( 'cases.caseStatusID' ),
            Field::inst( 'cases.createdBy' )->getFormatter( function ( $val, $data, $opts ) {return showName($val);}),
            Field::inst( 'cases.createdAt' ),
            Field::inst( 'cases.updatedAt' ),
            Field::inst( 'cases.updatedBy' )->getFormatter( function ( $val, $data, $opts ) { return showName($val);}),
            Field::inst( 'caseStatus.status' )
        );
    
        $data->leftJoin( 'caseStatus', 'caseStatus.caseStatusID', '=', 'cases.caseStatusID' );
        $data->join(
            Mjoin::inst( 'contacts' )
                ->link( 'cases.caseID', 'caseClient.caseID' )
                ->link( 'contacts.contactID', 'caseClient.contactID' )
                ->fields(
                    Field::inst( 'contactID' )
                        ->options( function () use ( $db ) {
                            $userList = $db->sql( "SELECT concat(contactLastName,', ',contactFirstName,' ',contactMiddleName) as name, contactID as id FROM contacts WHERE contactType != 'Company' order by contactLastName asc, contactFirstName asc" );
                            $out = array(array('label'=>'Select...','value'=>''));
                         
                            while ( $row = $userList->fetch() ) {
                                $out[] = array(
                                    "label" => $row['name'],
                                    "value" => $row['id']
                                );
                            }
                         
                            return $out;
                        } ),
                       Field::inst( 'contactType' )
                )
        );
             
    
        $data->on( 'preEdit', function ( $editor,$id,$values) {
    
            $editor->field( 'cases.updatedBy' )->setValue(setLastUserId());
            $editor->field( 'cases.updatedAt' )->setValue(date("Y-m-d H:i:s"));
             
        } )->on( 'preCreate', function ( $editor,$values) {
            $editor->field( 'cases.createdBy' )->setValue(setLastUserId());
            $editor->field( 'cases.createdAt' )->setValue(date("Y-m-d H:i:s")); 
        } );
    
    
    
    $out = $data->process( $_POST )->data();
    
    if(!isset($_POST['action'])){
      array_unshift($out["options"]["cases.companyBranchID"],array("label"=>"Select...","value"=>""));
    }
    
    //print_r($_POST);
    //print_r($out);
    echo json_encode( $out );
    
    
  • allanallan Posts: 63,516Questions: 1Answers: 10,473 Site admin

    I'd need the Javascript and also an example of the data loaded from the get and edit requests. Also the data submitted on edit.

    If you are able to publish it on a public server that would make it much easier to debug.

    Thanks,
    Allan

This discussion has been closed.