Complex Join Addbetween Pagination Stops

So the issue I’m having is when I add a between condition to a search criteria I’m using in a CActiveDataProvider that I’m returning to a CGrid everything appears to work okay; however, if you hit the next page button it always returns blank. If I take out the criteria. The grid works as expected and you can page forward and backwards.

I’m only including the part that’s in the model here if it would be helpful to see the rest I can add it.

I’ve looked through search after search and I can find lots of different issues but nothing seems to fix or apply to this issue. I’m hoping it’s something stupid I have done. Any help would be greatly appreciated.


[size=2]

	$oSomeCriteria = new CDbCriteria;[/size]

	$oSomeCriteria->select = 't.*';

	$oSomeCriteria->join = 'join callback_status callbackStatus on t.callback_status_id = callbackStatus.id ';

	$oSomeCriteria->join .= ' left join patient_visit_diagnosis patientVisitDiagnosis on patientVisitDiagnosis.patient_visit_id = t.id ';

	$oSomeCriteria->join .= ' left join diagnosis diagnosis on diagnosis.id = patientVisitDiagnosis.diagnosis_id ';

	$oSomeCriteria->join .= ' join visit_type visitType on visitType.id = t.visit_type_id ';

	$oSomeCriteria->group = 't.id,t.callback_status_id, callbackStatus.name';

	$oSomeCriteria->having = '((sum(diagnosis.call_flag)/count(diagnosis.id)) * (sum(visitType.call_flag)/count(visitType.call_flag)) < 1 and callbackStatus.name = \'Queued\') or callbackStatus.name in (\'Skipped\',\'Filtered\')';

	$oSomeCriteria->addBetweenCondition('t.visit_date',date('Y-m-d',strtotime($this->dStartDate)),date('Y-m-d',strtotime($this->dEndDate)));


	return new CActiveDataProvider(PatientVisit::model(), array(

			'criteria'=>$oSomeCriteria,

			'pagination'=>array('pageSize'=>50),[size=2]		[/size][size=2]));[/size]

Thanks,

Shelby J Hill

Wow hmm no help huh. Well I made a little progress. One of the issues I was having I guess was the problem where the totalItemCount would be incorrect because the count being pulled by the DataProvider would drop grouping/having clauses and come up with a larger number than expected. I’ve resolved that by setting the count manually. Now my issue is that when I click on the links for paging any search criteria that would have normally been passed in a post disappears so it performs the search with none. It does however now show the next page and such. What was happening before is I was hitting next page and because the total item count was higher than it should have been the page that was being shown was actually blank.

Also I removed all the manual joins above and put in proper relations and added a with clause.

Still can’t figure out why it’s dropping the search criteria when clicking the pagination links.