⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

[Solution] Flexigrid relation column ambiguous mysql error



marco811
  • profile picture
  • Member

Posted 02 July 2015 - 09:27 AM

Hi. I've had a big problem with this stuff. When i have a relation column in flexigrid, and i try to search any word dont work, mysql error:

Error Number: 1052</p><p>Column 'name' in where clause is ambiguous</p><p>

/topic/921-ajax-list-info-ambiguous-field-in-search/

 

 

I made a solution for this for the last version 1.5

 

Sorry for my bad english.

 

All you need to do is follow the next steps or download the php files

 

STEP 1) Grocery_crud_model.php, function get_list:

 

 

1.png

 

Replace //>>>> HERE <<<< string and paste this code and comment the next line:

$query = $this->db->get_compiled_select($this->table_name, TRUE);
        
foreach($this->relation as $rel) {
	$table = $rel[1];
	$query = str_replace('table_unique__' . $table . '__', constant('gc_table_unique_' . $table), $query); //INTRUSIVO
	}
$results = $this->db->query($query)->result();

Result:

 

2.png

 

STEP 2) Grocery_crud_model.php, function get_total_results:

 

3.png

Replace //>>>> HERE <<<< string and paste this code

$query = $this->db->get_compiled_select($this->table_name, TRUE);
                foreach($this->relation as $rel) {
                    $table = $rel[1];
                    $query = str_replace('table_unique__' . $table . '__', constant('gc_table_unique_' . $table), $query); //INTRUSIVO
                }
                return $this->db->query($query)->num_rows;

Result:

 

4.png

 

STEP 3) Grocery_crud_model.php, function join_relation:

 

5.png

 

Replace //>>>> HERE <<<< string and paste this code

define("gc_table_unique_" . $related_table, $unique_name);

Result:

6.png

 

STEP 4) Grocery_CRUD.php, function set_ajax_list_queries:

 

7.png

 

Replace the red selection with the next code:

$field_names = $this->_get_field_names_to_search($relation_values);
                                    if(is_array($field_names)) {
                                        $field_names[] = $relation_values[1];
                                    }
                                    
                                    $temp_relation[$this->_unique_field_name($relation_name)] = $field_names;

STEP 5) Grocery_CRUD.php, function set_ajax_list_queries:

8.png

Replace the red selection with the next code:

$temp_relation_arr = $temp_relation[$column->field_name];
                                                    $last_key = count($temp_relation_arr) - 1;
                                                    $table = $temp_relation_arr[$last_key];
                                                    unset($temp_relation_arr[$last_key]);
                                                    foreach($temp_relation_arr as $search_field)
                                                    {
                                                            $this->or_like('table_unique__' . $table . '__.' . $search_field, $search_text);
                                                    }

STEP 6) Grocery_CRUD.php, function set_ajax_list_queries:

 

9.png

Replace the red selection with the next code:

 
$this->or_like($this->basic_db_table . '.' . $column->field_name, $search_text);

END

 

Sorry again for my bad english

 

Enjoy!