Amit's Garage

A garage where one can get tools to solve their problems

Ambigious Field error when using relation

November 14, 2017 by BlakDronzer

Well,

PROBLEM
The base library of Grocerycrud still do have this issue of having ambigious field error. Why this occurs?  .. when we do a set relation and in the list, we try to run a search query, if it have overlapping / common field name in both the tables, then there are good chances of it having trouble of ambigous field issue as when the query is built upon, it is built using just the field name and not <table>.<field>name.

SOLUTION
Well – there is simple patch that once gone – the issue gets resolved.
Find the following function:


protected function set_ajax_list_queries($state_info = null)
{
....

In there, at the end of the function, replace the following (commented below) statement


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

Thats patch No.1.

Now, towards patch No. 2. Find the following function


protected function _get_field_names_to_search(array $relation_values)
{
....

In that, we need to add a patch the following line of code,


foreach($temp1 as $field)
	list($field_names_array[]) = explode('}',$field);

Now the additional patch


for($i=0; $i < count($field_names_array); $i++) { 
	$field_names_array[$i] = $this->_unique_join_name($relation_values[0]).'.'. $field_names_array[$i];

Thats it. That dose the trick of making a failsafe system and allowing you to have error free query even with common field in 2 tables in relation.

Share :  

969   BlakDronzer    Grocerycrud  
Total 0 Votes:
0
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Related Knowledge Base Posts -

  • How to show all the records together
  • Copy New Row
  • Add image uploader feature in Text Editor
  • Search Knowledgebase