Controlling new row inserted Left joined table

Controlling new row inserted Left joined table

crush123crush123 Posts: 417Questions: 126Answers: 18
edited April 2015 in Editor

Further to my Q in this post https://datatables.net/forums/discussion/27408/update-field-in-left-joined-table

I have an editor instance using a left join, which (now) works great when i update the record.

However, if I create a new record, a new row is also created in the left joined table.

In itself, this isn't necessarily a problem, but i need to do one of two things, (depending on an editor field value)

Either prevent the row being created in the joined table

or

take the newly PK id of the newlt created row and update the parent table, so that there is a relationship between them.

below is the php to generate the editor json...

$editor = Editor::inst( $db, 'tblcorporatedetails', 'CorporateID' )//table name and PKey(defaults to ID)

->field(
    Field::inst( 'tblcorporatedetails.CorporateID' ),
    Field::inst( 'tblcorporatedetails.MemberID' ),
    Field::inst( 'tblcorporatedetails.BusinessTypeID' ),
    Field::inst( 'tblcorporatedetails.CorporateDescription' ),
    Field::inst( 'tblcorporatedetails.CorporateURL' ),
    Field::inst( 'tblcorporatedetails.CorporateLogo' )
        ->upload(
        Upload::inst( function ( $file, $id ) {
        move_uploaded_file( $file['tmp_name'], $_SERVER['DOCUMENT_ROOT'].'/images/logos/'.$file['name'] );
        return $file['name'];
    } )
        ->allowedExtensions( array( 'png', 'jpg', 'bmp' ), "Please upload an image file (.pmg, .jpg, .bmp)" )
        ->validator( function ( $file ) {
              if ( $file['size'] >= 500000 ) {
                  return "Files must be smaller than 500Kb";
              }
              return null;
        } )
    ),
    Field::inst( 'tblcorporatedetails.ListOrder' ),
    Field::inst( 'refgrouptype.GroupTypeDescription' ),
    Field::inst( 'tblmembers.MembershipExpiresEnd' ),
    Field::inst( 'tblmembers.Complimentary' )
    ->setFormatter( function ( $val, $data, $opts ) {
                return ! $val ? 0 : 1;
            } ),
    Field::inst( 'tblmembers.PremiumMember' )
    ->setFormatter( function ( $val, $data, $opts ) {
                return ! $val ? 0 : 1;
            } )
)
->leftJoin('refgrouptype','refgrouptype.GroupTypeID', '=','tblcorporatedetails.BusinessTypeID')
->leftJoin('tblmembers','tblmembers.MemberID', '=','tblcorporatedetails.MemberID');
 $data = $editor
->process($_POST)
->data();

Answers

  • crush123crush123 Posts: 417Questions: 126Answers: 18

    Too complex for datatables editor ?

    I have a working php/mysql version, looks like i'll have to stick with that for now

This discussion has been closed.