CGridView MANY:MANY CDbCriteria

Hey everybody. I am fairly new to Yii and have a many:many CGridview where I am trying to filter based on ANY of the related table’s record’s NAME match the user selected filter value.

public function search()

 {...


 $criteria->addSearchCondition('SELECT COUNT(*) FROM birdshabitat join habitat where birdshabitat.birdid =  


 t.birdid and habitat.habitatid = birdshabitat.habitatid and habitat.habitat = "Fields")


 >0' ,'habitat',false, 'OR');

CDbException from this yii-created select:

SELECT COUNT() FROM birds t WHERE SELECT COUNT() FROM birdshabitat join habitat where birdshabitat.birdid = t.birdid and habitat.habitatid = birdshabitat.habitatid and habitat.habitat = "Fields") > 0 LIKE :ycp0

Can anybody tell me how to get rid of the "> 0 LIKE :ycp0" above? I have been working with this for 2 days now, so Thanks in advance for your help.

Andy

Can you show more about error message?

The SELECT failed because yii added that garbage onto the end

Why are you using addSearchCondition in the first place ?

Check it’d documentation - http://www.yiiframework.com/doc/api/1.1/CDbCriteria#addSearchCondition-detail

Hi, Use addSearchCondition here:

The first parameter is a colum, not sql query.