Yii Framework Forum: Access Related Table Columns Within Yii - Yii Framework Forum

Jump to content

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

Access Related Table Columns Within Yii Rate Topic: -----

#1 User is offline   kavitama 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 20-September 11

Posted 10 January 2014 - 01:00 PM

Hi,

I know how to access "one_plant" columns but NOT how to access "one_species" columns.

What is the cleanest way to do it from a CGridView or TbGridView stand point?

Regards
Kavi

Attached File(s)


0

#2 User is offline   nineinchnick 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 614
  • Joined: 12-September 11
  • Location:Bialystok, Poland

Posted 11 January 2014 - 06:11 AM

You're talking about grid column definition? You can use dots syntax like one_plant.one_species .
Don't be a dick.
0

#3 User is offline   kavitama 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 20-September 11

Posted 13 January 2014 - 12:07 PM

Hi NICK,

I think I've been not so clear in my asking.
I have a TbGridView on the table "one_plant_ event" and what i would like to be able is to access "one_species" fields from the grid considering that there is an "indirect" relationship between one_plant_event and "one_species".

So playing with the admin.php i would add lines like the following to see the fiels of one_species:

array(
'header' => Yii::t('app','Name In Argentine'),
'value' => 'xxxxx',
'filter' => 'xxxxx',
),

Hope is more clear

Regards
Kavi
0

#4 User is offline   nineinchnick 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 614
  • Joined: 12-September 11
  • Location:Bialystok, Poland

Posted 13 January 2014 - 12:17 PM

Indirect relations are supported by Yii. You can use the syntax I mentioned earlier. You can use relation name and then refer to one of it's attributes and Yii will fetch related objects automatically. This is done via lazy loading so if you want to prefetch everything in one query use eager loading by specifying the _with_ property in a CDbCriteria object. Read more in docs or in the guide.
Don't be a dick.
0

#5 User is offline   kavitama 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 20-September 11

Posted 13 January 2014 - 01:00 PM

I was looking at the guide and probably I didnt get it 100% but looking at this http://www.yiiframew...e-model-fields/ i find the solution.
In my case


array(
'header' => Yii::t('app','Name In Argentine'),
'value'=>'$data->plant->species->name_in_argentine',
),

made the solution appear.

NOw I am looking for the filter solution but first I will be checking a bit more.

Regards
Kavi
0

#6 User is offline   nineinchnick 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 614
  • Joined: 12-September 11
  • Location:Bialystok, Poland

Posted 13 January 2014 - 03:11 PM

You could just declare the columns as string: 'plant.species.name_in_argentine:'.Yii::t('app','Name In Argentine')
Don't be a dick.
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