Unknown parameter for md02_title.name in row 0

Unknown parameter for md02_title.name in row 0

logisticslogistics Posts: 6Questions: 2Answers: 0
edited August 2015 in Editor

In the following situation I get constantly the message that md02_title.name is an unknown parameter for row 0.

md02_usr: title_id = [1|2]
md02_title: id=1 -> name='Mw.', id=2 -> name='Dhr.'

Parts of js:

  1. "fields": [{label: "Titel", name: "md02_usr.title_id", type: "selec"t}]
  2. $('#modUsr').DataTable ({ columns [{ (data: "md02_title.name"}] })

Parts of PHP:

  1. Field::inst( 'md02_usr.title_id' )->options('md02_title', 'md02_title.id', 'md02_title.name'),
  2. ->leftJoin( 'md02_title', 'md02_title.id', '=', 'md02_usr.title_id' )

I have searched for this error some hours and I have changed a lot, but as far as I know the above is OK. Row 0 contains the valus 1 or 2, that's for sure.

Any idea what I oversee?

regards, Niek.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,821Questions: 1Answers: 10,127 Site admin

    Hi Niek,

    Could you possible show me the full PHP you are using and also a debug trace for your table?

    Thanks,
    Allan

  • logisticslogistics Posts: 6Questions: 2Answers: 0
    edited August 2015

    Hi Allen,

    You can find the debug trace in : usiwex.

    The complete contents of my PHP-function is:

    <?php
    
    ini_set('display_errors', 'On');
    error_reporting(E_ALL);
    require_once('../inc-general/main_functions.php');
    require_once('../inc/main_config.php');
    require_once('../inc-general/connMySql.php');
    dumpDataPHP("modUsr.php[" . __LINE__ . "]->FlowStart", "", "a");
    dumpDataPHP("modUsr.php[" . __LINE__ . "]->Request\n", $_REQUEST, "a");
    
    // DataTables PHP library
    include( "../dt/extensions/editor/php/DataTables.php" );
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Join,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    $visitorId = isset($_POST['visitorId']) ? $_POST['visitorId'] : 0;
    
    /*
     * Example PHP implementation used for the join.html example
     */
        dumpDataPHP("modUsr.php[" . __LINE__ . "]->db: ", $db, "a");
    Editor::inst( $db, 'md02_usr' )
        ->field(
            Field::inst( 'md02_usr.id' ),
            Field::inst( 'md02_usr.usrname' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'md02_usr.title_id' )
                ->options('md02_title', 'md02_title.id', 'md02_title.name'),
            Field::inst( 'md02_usr.firstname' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'md02_usr.middlename' ),
            Field::inst( 'md02_usr.lastname' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'md02_usr.email' ),
            Field::inst( 'md02_usr.deleted' )->validator( 'Validate::numeric' ),
            Field::inst( 'md02_usr.created' )
                ->set( Field::SET_CREATE )
                ->setValue( date('Y-m-d') ),
            Field::inst( 'md02_usr.modified' ) // no need to use SET_BOTH - it is the default value
                ->setValue( date('Y-m-d') ),
            Field::inst( 'md02_usr.usrid_mod' )
                ->setValue( $visitorId ))
        ->leftJoin( 'md02_title', 'md02_title.id', '=', 'md02_usr.title_id' )
        ->where( 'md02_usr.id', 19, '>' )
        ->where( 'deleted', 0, '=' )
        ->process($_POST)
        ->json();
    dumpDataPHP("modUsr.php[" . __LINE__ . "]->FlowEnd", "", "a");
    

    Regards, Niek.

  • allanallan Posts: 61,821Questions: 1Answers: 10,127 Site admin
    Answer ✓

    Thanks. If you have a look at the JSON data being returned by the server you will see that indeed md02_title.name is not defined in the data. In fact there is no md02_title object at all.

    The reason for this is that there are no fields that obtain that data from the joined table (the options for md02_usr.title_id get it, but that isn't a field - just options).

    So you need to add:

    Field::inst( 'md02_title.name' )
    

    to your fields. You may also want to add ->set( false ) to it just to protect it from being written to.

    Allan

  • logisticslogistics Posts: 6Questions: 2Answers: 0

    Hi iAllen,

    Thanks. This worked immediately (as you already knew of course :-) )

    Regards, Niek

This discussion has been closed.