Need Extra Data Set access in createdRow

Need Extra Data Set access in createdRow

INTONEINTONE Posts: 153Questions: 58Answers: 6

I am trying to get access to extra data in the createRow of dataTables but that data set is not accessible. I create the dataset from the server like this:


$data = Editor::inst( $db, 'message', 'message.messageID' ) ->fields( ///fields ); $out = $data->process( $_POST )->data(); if(!isset($_POST['action'])){ $out['isRead'] = $data->db()->sql( " SELECT a.`createdBy`,b.`isRead`,b.`messageID`,b.`recipientID` FROM message a, messageRecipient b WHERE a.`messageID` = b.`messageID` ORDER BY a.createdAt DESC")->fetchAll(); } echo json_encode( $out );

This question has an accepted answers - jump to answer

Answers

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

    I'm not clear on what extra data it is that you are string to access. Could you clarify your question a little please?

    Allan

  • INTONEINTONE Posts: 153Questions: 58Answers: 6

    I am building a simple messaging system. I have a table called message and another called messageRecipient. 'message' store the message while message recipient store the ids of all those who got the message plus 'isRead' and 'isReadDate'. I am already using a mjoin on the contacts table to get the people to sent the message to. I know I can use mjoin the get the extra data from the messageRecipient table but I do not want to write any I just want to read, hence my additional query at the bottom in the

    if(!isset($_POST['action'])){}
    

    block. Here is my summarized code:

    $data = Editor::inst( $db, 'message', 'message.messageID' )
    ->fields(
        //fields
    )->join(
            Mjoin::inst( 'contacts' )
                ->link( 'message.messageID', 'messageRecipient.messageID' )
                ->link( 'contacts.contactID', 'messageRecipient.recipientID' )
                ->fields(
                    Field::inst( 'contactID' )
                        ->validator( 'Validate::required' )
                        ->options( function () use ( $db ) {
                            $userList = $db->sql( "query" );
                           
                            $out = array();
                            while ( $row = $userList->fetch() ) {
                                $out[] = array(
                                    "label" => $row['name'],
                                    "value" => $row['id']
                                );
                            }
                         
                            return $out;
                        } )
                )
      );
     
    $out = $data->process( $_POST )->data();
     
    if(!isset($_POST['action'])){
     
    //extra data about each message
     $out['isRead'] = $data->db()->sql( " SELECT a.`createdBy`,b.`isRead`,b.`messageID`,b.`recipientID`
                                                                 FROM message a, messageRecipient b
                                                              WHERE a.`messageID` = b.`messageID`
                                                         ORDER BY a.createdAt DESC")->fetchAll();
    }
     
    echo json_encode( $out );
    

    The problem is that I am seeing isRead dataset but it is not accessible in the createRow of datatables.

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

    I know I can use mjoin the get the extra data from the messageRecipient table but I do not want to write any I just want to read

    Use use Mjoin->set( false ) in that case and keep it in the Mjoin.

    The problem is that I am seeing isRead dataset but it is not accessible in the createRow of datatables.

    No - you would need to merge it into the data array that contains the information about each row.

    Allan

This discussion has been closed.