⚠ 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

custom model filter ambigous



Racing Chocobo
  • profile picture
  • Member

Posted 06 August 2013 - 17:55 PM

Hi guys,

 

I have some problems with custom model while implementing filter function.

I went through the forum and find about this problem, and I find a solution about the filtering, by adding something like this:

function get_total_results() {

      $this->db->from($this->table_name);

      $this->db->join();
    
      return $this->db->count_all_results();
}

However, this solution works well in general multi join table that has different field name, but whenever I met with two join table that has same field name, it will occur error:

 

Column 'content' in where clause is ambiguous

 

I realized this problem occured since I've joined two tables that has field name 'content' separately, so when I do the filter function for the column 'content', it will say that it ambigous.

 

It's is there any implementable method to handle with this problem?

 

I've tried so many method to solved this problem, but nothing worked until now.

 

Thousands of thanks for you all~


davidoster
  • profile picture
  • Member

Posted 07 August 2013 - 04:49 AM

Try to use the following structure on the field names;

tablename.fieldname. This might resolve it.


Racing Chocobo
  • profile picture
  • Member

Posted 07 August 2013 - 13:27 PM

Yeah, I've tried for many2 times and many method, but still can't solved this problem, the problem is because everytime it filter, it only throw the 'content' instead of tablename.fieldname

I donno whether my method is wrong for getting the tablename.fieldname or any other problems, I've tried so many times, but still can't work.

$_select = array(
       'missions.sn, missions.target_num, mission_type.name, mission_text.content, good_text.title'
       );

that's one of my tries, I've already put the tablename before the fieldname, but while it do filtering, it still only search for 'content' instead of 'mission_text.content'

Thank you very much for the reply~


davidoster
  • profile picture
  • Member

Posted 07 August 2013 - 21:57 PM

Well I propose you enable the profiler to see what is going on with the queries that are generated.

In general follow these guidelines for debugging.


Amit Shah
  • profile picture
  • Member

Posted 12 August 2013 - 14:26 PM

Well David,

i did encounter this issue in past. I did alter the grocery crud base library to fix it. When looking for filter, if not mistakend it was in - set_ajax_list_queries

i managed to fix it with adding _unique_field_name call to some other places too - it sets it if there is an relation to avoid the abmigious field call .. but for some reason, i still was getting it and i had set it other places too.. and the problem was solved..

 

Here also a similar approach may be applied to get the desired result set if i find the code some place, i surely will post it.. but if i dont, .. the above solutuion specified is a good way to solve.