Yii Framework Forum: CGridView MANY:MANY CDbCriteria - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CGridView MANY:MANY CDbCriteria Getting CGridView to filter on column in related table Rate Topic: ***** 1 Votes

#1 User is offline   abester 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 30-September 11
  • Location:Asheville, N.C. US

Posted 26 October 2011 - 12:54 PM

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
0

#2 User is offline   Khoa Le 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 11-April 11

Posted 26 October 2011 - 01:58 PM

Can you show more about error message?
0

#3 User is offline   abester 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 30-September 11
  • Location:Asheville, N.C. US

Posted 26 October 2011 - 06:52 PM

The SELECT failed because yii added that garbage onto the end
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 27 October 2011 - 03:34 AM

Why are you using addSearchCondition in the first place ?

Check it'd documentation - http://www.yiiframew...ondition-detail
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   Khoa Le 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 11-April 11

Posted 27 October 2011 - 03:51 AM

Hi, Use addSearchCondition here:

Quote

public CDbCriteria addSearchCondition(string $column, string $keyword, boolean $escape=true, string $operator='AND', string $like='LIKE')

The first parameter is a colum, not sql query.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users