Join / order

Join / order

nskwortsownskwortsow Posts: 120Questions: 0Answers: 0
edited November 2012 in General
Hi,
I have two tables:

tblExerciseEquipment and tblLanguages. The latter table is for internationalization.

So 1 piece of equipment (e.g. "ball") could be translated into n languages.

The link between the tables is tblExerciseEquipment.f_LanguageID and tblLanguages.LanguageID

On the SERVER SIDE, I have the following code:

$editor = Editor::inst( $db, 'tblExerciseEquipment' )
->fields(
Field::inst( 'EquipmentName' )->validator( 'Validate::required' ),
Field::inst( 'f_LanguageID' )->validator( 'Validate::required' )
)
->join(
Join::inst('tblLanguages','array')
->join('f_LanguageID','LanguageID')
->fields(
Field::inst( 'LanguageID' )->validator( 'Validate::required' ),
Field::inst( 'LName' ))
);

$out = $editor
->pkey('EEquipmentID')
->process($_POST)
->data();

if ( !isset($_POST['action']) ) {
// Get department details
$out['tblLanguages'] = $db
->select( 'tblLanguages', 'LanguageID as value, LName as label' )
->fetchAll();

}

On the CLIENT SIDE, I have:

var editor;

$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": "ajax_content_exerciseEquipment.php",
"domTable": "#tblExerciseEquipment",
"fields": [ {
"label": "Language:",
// The 'id' value from the property is used to set the value
// of the select list.
"name": "f_LanguageID",
"type": "select"
}, {
"label": "Equipment name:",
// 'name' here will generate an array of the 'id' properties from
// the access parameter for the row's data and use that to enable
// the correct checkboxes.
"name": "EquipmentName"
}
]
} );

$('#tblExerciseEquipment').dataTable( {
"sDom": "Tfrtip",
"sAjaxSource": "ajax_content_exerciseEquipment.php",
"aoColumns": [
{
// Use the 'name' property from the 'dept' object in the
// JSON. It might not be set, so we also provide a default.
"mData": "tblLanguages.LName",
"sDefaultContent": ""
},
{ "mData": "EquipmentName" }

],
"oTableTools": {
"sRowSelect": "single",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
},
"fnInitComplete": function ( settings, json ) {
editor.field('f_LanguageID').update( json.tblLanguages );
}
} );
} );

When I submit the form, I receive the following error:

Undefined index: tblLanguages in /Users/xxx/functions/datatables/Editor/Join.php on line 474

#

What am I doing wrong here? I have been SQL programming since 1998, but am rather confused with the order of the statements that are required here.

});

Replies

  • nskwortsownskwortsow Posts: 120Questions: 0Answers: 0
    I've looked at this again.

    The data is being updated correctly (in the tblExerciseEquipment), but still I get the error.

    Is Datatables trying to update the data in both tables?

    The Query that should be executed is:

    UPDATE tblExerciseEquipment SET EquipmentName = 'Foo',f_LanguageID = 'BAR' WHERE EEquipmentID = X

    #

    Is my server side code correct for this?
  • nskwortsownskwortsow Posts: 120Questions: 0Answers: 0
    Deleting works (no error)
    Updating & creating work, but generate the following error:

    ###

    Notice: Undefined index: tblLanguages in /Users/xxx/datatables/Editor/Join.php on line 496

    {"id":"row_5","error":"","fieldErrors":[],"data":[],"row":{"DT_RowId":"row_5","EquipmentName":"Cord","f_LanguageID":"0","tblLanguages":{"LanguageID":"0","LName":"English"}}}
  • nskwortsownskwortsow Posts: 120Questions: 0Answers: 0
    This is the POSTED data:
    action=create&table=&id=&data%5Bf_LanguageID%5D=0&data%5BEquipmentName%5D=Ball

    This is the RESULT:

    Notice: Undefined index: tblLanguages in /Users/nathan/Sites/Physitrack.com/functions/datatables/Editor/Join.php on line 471
    {"id":"row_7","error":"","fieldErrors":[],"data":[],"row":{"DT_RowId":"row_7","EquipmentName":"Ball","f_LanguageID":"0","tblLanguages":{"LanguageID":"0","LName":"English"}}}

    #

    I don't see why tblLanguages is involved at all in the JOIN. I am not updating this table (it only holds values to support the parent table).
  • nskwortsownskwortsow Posts: 120Questions: 0Answers: 0
    Figured it out.
    Need to use:
    ->set( false )

    This is not clear. Please update your documentation by showing SQL queries translated to your API.
This discussion has been closed.