I'm having a problem when using $crud->where() and use search on all columns.
This is my code:
$crud = new grocery_CRUD(); $crud->where('leads.deleted','0'); $crud->set_table('leads'); $crud->set_subject('Lead'); $crud->set_primary_key('id'); $crud->columns('firstname','lastname','email','street','country', 'locale_id'); $crud->display_as('firstname','First name') ->display_as('lastname','Last name') ->display_as('email','Email address') ->display_as('locale_id','Language') ->display_as('agent_id','Agent') ->display_as('sex_id','Gender') ->display_as('lead_type_id','Lead type'); $crud->set_relation('locale_id','locales','name'); $crud->set_relation('lead_type_id','lead_types','name'); $crud->set_relation('sex_id','sexes','name'); $crud->set_crud_url_path('/leads'); $crud->unset_add_fields('deleted'); $crud->unset_edit_fields('agent_id', 'coworker_id', 'deleted'); $crud->change_field_type('agent_id','invisible'); $crud->change_field_type('coworker_id','invisible'); $crud->required_fields('firstname', 'lastname', 'date_of_birth', 'email', 'phone'); $crud->callback_before_update(array($this,'set_agent_coworker')); $crud->callback_before_insert(array($this,'set_agent_coworker')); $crud->callback_delete(array($this,'set_deleted_one')); $output = $crud->render(); $this->load->view('leads', $output);
Request url:
/leads/ajax_list_info
Request parameters:
This is the error being thrown:
A Database Error Occurred
Error Number: 1054
Unknown column 'leads.deleted' in 'having clause'
SELECT COUNT(*) AS `numrows`FROM (`leads`)LEFT JOIN `locales` as j6a51f7a4 ON `j6a51f7a4`.`id` = `leads`.`locale_id`LEFT JOIN `lead_types` as j9990a220 ON `j9990a220`.`id` = `leads`.`lead_type_id`LEFT JOIN `sexes` as je5ad4385 ON `je5ad4385`.`id` = `leads`.`sex_id`WHERE `leads`.`deleted` = '0'AND `firstname` LIKE '%sch%'OR `lastname` LIKE '%sch%'OR `email` LIKE '%sch%'OR `street` LIKE '%sch%'OR `country` LIKE '%sch%'OR `j6a51f7a4`.`name` LIKE '%sch%'HAVING `leads`.`deleted` = '0'
Filename: /models/grocery_crud_model.php
Line Number: 191
The way to solve this problem is to add the HAVING column(s) to the SELECT part. You CANNOT put columns in the HAVING clause without selecting them first!
Could this please be fixed?