Yii Framework Forum: Search By Related Field - Yii Framework Forum

Jump to content

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

Search By Related Field Rate Topic: -----

#1 User is offline   jozek; 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 15-February 13

Posted 04 March 2013 - 07:44 AM

Hi,

I know there are plenty of topics on this but I searched&tried so many and it is still not working.
I tried those for example:
1. http://www.yiiframew...l-in-cgridview/
2. http://www.yiiframew...eld#entry168484

I have tables: Team and Worker. Any worker can be assigned to a Team. So at the Workers Manager I want to search Workers also by Team name.
I got the column etc. but when I type part of team name - search starts but the written text dissappears and search doesn't care about the field. I checked the AJAX call with Firebug and there is a field called teamName (I added public field to my Worker model class). But when I print_r criteria in my search method - there is no condition.
How is that possible? How can I perform the searching by related field?
0

#2 User is offline   le_top 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 303
  • Joined: 08-June 10
  • Location:France

Posted 04 March 2013 - 08:18 AM

How about trying my RelatedSearchBehavior extension.
0

#3 User is offline   jozek; 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 15-February 13

Posted 04 March 2013 - 08:30 AM

It does work, thanks. I just wanted to do it the way the guide provide - so I was surprised it is not working (altough people say it does).

One question @le_top - I noticed that it's working only with default search method. Is it possible to define for example relatedSearch() method and do the search there?

The other thing - is it possible to pass constant 'NOT LIKE' parameter to the search programmatically?
0

#4 User is offline   le_top 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 303
  • Joined: 08-June 10
  • Location:France

Posted 04 March 2013 - 11:51 AM

Hi
If you want to add a constant 'NOT LIKE' comparison on a relation with the RelatedSearchBehavior you could define a specific related attribtute for that and set the value of the attribute to "<>SEARCH_TEXT".
0

#5 User is offline   Stageline 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 03-February 12

Posted 16 March 2013 - 01:22 PM

Hello!

I have problem with model search & cdbcriteria. (some parts in hungarian lang.)

1. Jqcalendar model, this have HAS_MANY "jarmuvek" relation ( Foglaltjarmu[] ) One jqcalendar record have many Foglaltjarmu rows

@property Foglaltjarmu[] $jarmuvek
'jarmuvek' => array(self::HAS_MANY, 'Foglaltjarmu', 'FuvarID'),

2. Foglaltjarmu[] model, this have BELONGS_TO jarmu relation ( Flotta model ) One Foglaltjarmu record have one jarmu record.

@property Flotta $jarmu
'jarmu' => array(self::BELONGS_TO, 'Flotta', 'jarmuID'),

How do i search jarmu.rendszam field in Jqcalendar model? It possible? ex. group by?

Manual sql query: select * from jqcalendar left join foglaltjarmu on foglaltjarmu.FuvarID = jqcalendar.Id left join Flotta on Flotta.id = foglaltjarmu.jarmuID where Flotta.rendszam = 'HOS-108' group by .....

This does not work for me.

	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
		$criteria->with = array('jarmuvek');
		$criteria->compare('jarmu.rendszam',$this->rendszam);


Thanks.

Edit: Solved.

'jarmuvek' => array(self::HAS_MANY,'Foglaltjarmu','FuvarID','with'=>'jarmu'),

Attached File(s)

  • Attached File  db.jpg (278.14K)
    Number of downloads: 15

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