⚠ 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

Search doesn't work when using or_where



grocerycruduser1
  • profile picture
  • Member

Posted 23 January 2014 - 22:36 PM

So I have a table that I am using a $this->grocery_crud->where('isTest',1) and then I do two or_where conditions. If I comment out the or_where conditions, the CRUD's column searching works fine.  If I change the or_where calls into where calls, the CRUD shows a lot less rows, but the search functionality works. It's only when I do an or_where that I get messed up search results.

 

I think the messed up results might be related to my set_relation calls.  Here is the code:

 

        $this->grocery_crud->set_table('xxx');
 
        $this->grocery_crud->where('isTest',1);
        $this->grocery_crud->or_where('contract',0);
        $this->grocery_crud->or_where('funnel',0);       
 
        $this->grocery_crud->columns('company','test_flight_name','variation','engagement_start_date','contract', 'funnel','pm','cm','analyst','developer','creative');
        $this->grocery_crud->edit_fields('company','test_flight_name','variation','engagement_start_date','contract', 'funnel','pm','cm','analyst','developer','creative');
        $this->grocery_crud->add_fields('company','test_flight_name','variation','engagement_start_date','contract', 'funnel','pm','cm','analyst','developer','creative','isTest');
        $this->grocery_crud->field_type('isTest', 'hidden', 1);
 
        $this->grocery_crud->display_as('pm','PM');
        $this->grocery_crud->display_as('cm','CM');
 
        $this->grocery_crud->set_relation('company','client','name');
        $this->grocery_crud->set_relation('contract', 'contract', 'name');
        $this->grocery_crud->set_relation('funnel', 'funnel', 'name');
        $this->grocery_crud->set_relation('pm','users','{first_name} {last_name}');
        $this->grocery_crud->set_relation('cm','users','{first_name} {last_name}');
        $this->grocery_crud->set_relation('analyst','users','{first_name} {last_name}');
        $this->grocery_crud->set_relation('developer','users','{first_name} {last_name}');
        $this->grocery_crud->set_relation('creative','users','{first_name} {last_name}');
 

 

 

Anyone know why this could be happening?


grocerycruduser1
  • profile picture
  • Member

Posted 20 March 2014 - 17:37 PM

I found the solution here:

 

https://github.com/scoumbourdis/grocery-crud/issues/265

 

 

The problem is that the CRUD's MySQL query is not specifying a database name before the table names, so you end up having duplicate column names sometimes when you are doing set_relation because of the JOINs.