diff --git a/js/sql.js b/js/sql.js index 9adfb62d6..15c780f2d 100644 --- a/js/sql.js +++ b/js/sql.js @@ -542,6 +542,11 @@ $(document).ready(function() { * @var relation_curr_value String current value of the field (for fields that are foreign keyed). */ var relation_curr_value = $this_field.find('a').text(); + /** + * @var relation_key_or_display_column String relational key if in 'Relational display column' mode, + * relational display column if in 'Relational key' mode (for fields that are foreign keyed). + */ + var relation_key_or_display_column = $this_field.find('a').attr('title'); /** * @var curr_value String current value of the field (for fields that are of type enum or set). */ @@ -647,7 +652,8 @@ $(document).ready(function() { 'table' : window.parent.table, 'column' : field_name, 'token' : window.parent.token, - 'curr_value' : relation_curr_value + 'curr_value' : relation_curr_value, + 'relation_key_or_display_column' : relation_key_or_display_column } $.post('sql.php', post_params, function(data) { diff --git a/sql.php b/sql.php index 41f1ec6a8..50026b92b 100644 --- a/sql.php +++ b/sql.php @@ -63,8 +63,17 @@ if (isset($_REQUEST['get_relational_values']) && $_REQUEST['get_relational_value $column = $_REQUEST['column']; $foreigners = PMA_getForeigners($db, $table, $column); + $display_field = PMA_getDisplayField($foreigners[$column][foreign_db], $foreigners[$column][foreign_table]); + $foreignData = PMA_getForeignData($foreigners, $column, false, '', ''); + if ($_SESSION['tmp_user_values']['relational_display'] == 'D' + && (isset($display_field) && strlen($display_field) + && (isset($_REQUEST['relation_key_or_display_column']) && $_REQUEST['relation_key_or_display_column']))) { + $curr_value = $_REQUEST['relation_key_or_display_column']; + } else { + $curr_value = $_REQUEST['curr_value']; + } if ($foreignData['disp_row'] == null) { //Handle the case when number of values is more than $cfg['ForeignKeyMaxLimit'] $_url_params = array( @@ -78,7 +87,7 @@ if (isset($_REQUEST['get_relational_values']) && $_REQUEST['get_relational_value .'>' . __('Browse foreign values') . ''; } else { - $dropdown = PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $_REQUEST['curr_value'], $cfg['ForeignKeyMaxLimit']); + $dropdown = PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $curr_value, $cfg['ForeignKeyMaxLimit']); $dropdown = ''; }