[SOLVED]'bond With' in cDbCriteria for search() in CGridView with join and condition missing

Hi,

I have this in my search function model:




public function search()

	{

		$criteria=new CDbCriteria;

		$criteria->alias = 'mb1';

		

		//$criteria->compare('mb1.id',$this->id);

		$criteria->compare('mb1.user_fk',$this->user_fk);

		$criteria->compare('mb1.payment_fk',$this->payment_fk);

		$criteria->compare('mb1.no_siri',$this->no_siri,true);


		

		$criteria->join = 'LEFT JOIN M_B as mb2 ON mb1.no_siri = mb2.no_siri AND mb1.id < mb2.id';  //[Line-1]

		$criteria->condition = 'mb2.no_siri IS NULL'; //[Line-2]


		return new CActiveDataProvider(get_class($this), array(

			'criteria'=>$criteria,

		));

	}



It runs pretty fine without [Line-1] and [Line-2] when I select filter in search view.

From log:




Querying SQL: SELECT * FROM `M_B` `mb1` WHERE

mb1.jenis_bayaran_fk=:ycp0 ORDER BY

mb1.status_bayaran_fk LIMIT 10. Bound with :ycp0='2'



When run with both line, the filter is not working anymore.

The log:




Querying SQL: SELECT `mb1`.`user_fk`, `mb1`.`user_fk`,

`mb1`.`payment_fk`, `mb1`.`no_siri`

 FROM `M_B` `mb1` LEFT JOIN M_B as mb2 ON

mb1.no_siri = mb2.no_siri AND mb1.id < mb2.id WHERE

mb2.no_siri IS NULL  LIMIT 10.

Bound with :ycp0='2'



I notice the bond ycp0 is missing.

What Im trying to do is to list out all latest row of that Siries number.

Example: User A pay 2 times for siries 0001. I want to just display the 2nd payment only.

The SQL statement I have is from www[.]artfulsoftware[.]com/infotree/queries.php#101




Select mb1.*

FROM M_B as mb1

LEFT JOIN M_B as mb2 ON mb1.no_siri = mb2.no_siri AND mb1.id < mb2.id

WHERE mb2.no_siri IS NULL



How can I do this?

Thanks

Hi,

Anyone can help me with this please?

check this answer to a thread with the same problem - http://www.yiiframework.com/forum/index.php?/topic/17115-got-a-bug-for-cdbcriteria-of-yii-116/page__view__findpost__p__84843

Thank you, that answers my question.

Im always end with condition, Im pretty new to Yii.