2

Sorry ... my english is bad, so my question could be absolutely not clear.

I have this tables: Groups Users Reports

Relations: Groups 1 -> N Users 1 -> N Reports

In the admin view of report I'm using a CGridView.

i'm actually able to show user name. ... but what about show group.name ?

How to setup relations ? How to setup CDbCriteria ?

I already have this relation In Report model:

'user' => array(self::BELONGS_TO, 'Users', 'userId'),

And this in User model

'group' => array(self::BELONGS_TO, 'Gruppi', 'groupId'),

In Report Model I have this:

$criteria=new CDbCriteria;
$criteria->with = array ('user');
realtebo
  • 23,922
  • 37
  • 112
  • 189

2 Answers2

1

You should be able to get the group.name like this(from report's admin view):

user.group.name

And your current relations will do, also you do not have to use any criteria.

bool.dev
  • 17,508
  • 5
  • 69
  • 93
  • Please:.. see this: http://stackoverflow.com/questions/12873347/yii-how-to-sort-and-search-in-a-cgridview-column-with-a-two-level-1-n-relation – realtebo Oct 13 '12 at 13:00
0

You can also use like this:-

$criteria->with = array('user', 'user.group');
group.name

One more solution for the problem. (Tested)

shane
  • 11
  • 2