⚠ 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

[BUG] in HAVING clause when using where and search



Ruben Vanhoeyveld

Ruben Vanhoeyveld
  • profile picture
  • Member

Posted 19 September 2013 - 18:11 PM

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:

search_text: sch
search_field:
per_page: 25
order_by[0]: firstname
order_by[1]: asc
page: 1
 

 

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?


davidoster

davidoster
  • profile picture
  • Member

Posted 20 September 2013 - 20:16 PM

Hello and welcome to the forums [member=Ruben Vanhoeyveld].

Could you please post this as an issue at : https://github.com/scoumbourdis/grocery-crud/issues

Thank you.


Ruben Vanhoeyveld

Ruben Vanhoeyveld
  • profile picture
  • Member

Posted 27 September 2013 - 22:12 PM

I can't get this fixed.. Can anyone look at this?


davidoster

davidoster
  • profile picture
  • Member

Posted 29 September 2013 - 06:48 AM

Did you post an issue on github? If yes then you need to wait.


wdj315

wdj315
  • profile picture
  • Member

Posted 08 July 2018 - 10:22 AM

Did you post an issue on github? If yes then you need to wait.

He did,but it seems no one take care  :(  https://github.com/scoumbourdis/grocery-crud/issues/243

It had been 5 years ago....  :o

I have same issue and after some headcache time, I find a solution.

Even I don't think this is a good one, but it did solve my problem for now.

just mark these three line in Grocery_CRUD.php around line 643

				/*if(!empty($this->where))
					foreach($this->where as $where)
						$this->basic_model->having($where[0],$where[1],$where[2]);*/

still hope someone can figure out and fix that bug:)


rumena

rumena
  • profile picture
  • Member

Posted 05 November 2019 - 10:06 AM

 

He did,but it seems no one take care  :(  https://github.com/scoumbourdis/grocery-crud/issues/243

It had been 5 years ago....  :o

I have same issue and after some headcache time, I find a solution.

Even I don't think this is a good one, but it did solve my problem for now.

just mark these three line in Grocery_CRUD.php around line 643

				/*if(!empty($this->where))
					foreach($this->where as $where)
						$this->basic_model->having($where[0],$where[1],$where[2]);*/

still hope someone can figure out and fix that bug:)

 

Thank you, wdj315 ! Your solution works for me.