Yii Framework Forum: Dataprovider With Complicated Relations - Yii Framework Forum

Jump to content

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

Dataprovider With Complicated Relations Rate Topic: -----

#1 User is offline   tzoll 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 28-February 13

Posted 02 April 2013 - 02:39 AM

Hello. I've got this kind of problem:

I've got 3 db tables (and models) and defined relations inside this models:

Obserwacje(id, id_gatunku); relacje:'idGatunku' => array(self::BELONGS_TO, 'Gatunki', 'id_gatunku'),
Gatunki(id,nazwa_gatunku,id_grupy ); relacje:'nazwaGrupy' => array(self::BELONGS_TO, 'GrupyGatunkow', 'id_grupy'),
GrupyGatunkow(id, nazwa) (bez relacji)


Additional, in "Obserwacje" model
1) i have defined $public grupa_szukaj
2) in search() function i added this $criteria:

$public grupa_szukaj;

$criteria->with = array('idGatunku');   


My question is: how can I make a search in view of Obserwacje based on the field name of the model GrupyGatunkow (i know that i have to define $criteria->compare in search() function in Obserwacje model, but this defined by me doesn't work:

$criteria->compare('idGatunku.nazwaGrupy.nazwa', $this->grupa_szukaj, true );  
$criteria->compare('idGatunku->nazwaGrupy->nazwa', $this->grupa_szukaj, true ); 


p.s. this is my code from Obserwacje view:
<?php $this->widget('bootstrap.widgets.TbGridView',array( 
	'dataProvider'=>$model->search(),
	'columns'=>array(       
                array(
                    'name'=>'grupa_szukaj',
                    'value'=>'$data->idGatunku->nazwaGrupy->nazwa'), 
		array(
			'class'=>'bootstrap.widgets.TbButtonColumn',
		),
	),
)); ?>


Thanks for help
Greetings
Tom
0

#2 User is online   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,450
  • Joined: 04-March 10
  • Location:UK

Posted 02 April 2013 - 03:01 AM

Does this help?
0

#3 User is offline   Stageline 

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

Posted 02 April 2013 - 03:02 AM

View Posttzoll, on 02 April 2013 - 02:39 AM, said:

Hello. I've got this kind of problem:

I've got 3 db tables (and models) and defined relations inside this models:

Obserwacje(id, id_gatunku); relacje:'idGatunku' => array(self::BELONGS_TO, 'Gatunki', 'id_gatunku'),
Gatunki(id,nazwa_gatunku,id_grupy ); relacje:'nazwaGrupy' => array(self::BELONGS_TO, 'GrupyGatunkow', 'id_grupy'),
GrupyGatunkow(id, nazwa) (bez relacji)


Additional, in "Obserwacje" model
1) i have defined $public grupa_szukaj
2) in search() function i added this $criteria:

$public grupa_szukaj;

$criteria->with = array('idGatunku');   


My question is: how can I make a search in view of Obserwacje based on the field name of the model GrupyGatunkow (i know that i have to define $criteria->compare in search() function in Obserwacje model, but this defined by me doesn't work:

$criteria->compare('idGatunku.nazwaGrupy.nazwa', $this->grupa_szukaj, true );  
$criteria->compare('idGatunku->nazwaGrupy->nazwa', $this->grupa_szukaj, true ); 


p.s. this is my code from Obserwacje view:
<?php $this->widget('bootstrap.widgets.TbGridView',array( 
	'dataProvider'=>$model->search(),
	'columns'=>array(       
                array(
                    'name'=>'grupa_szukaj',
                    'value'=>'$data->idGatunku->nazwaGrupy->nazwa'), 
		array(
			'class'=>'bootstrap.widgets.TbButtonColumn',
		),
	),
)); ?>


Thanks for help
Greetings
Tom


link
1

#4 User is offline   tzoll 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 28-February 13

Posted 02 April 2013 - 03:15 AM

Thanks Stageline, it works well :) Solved :)
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