0

In Yii, I have a relations set up that use the through option.

public function relations()
    {
        return array(
            'users_relationships' => array(
                self::HAS_MANY, 'EnvironmentUsers', 'environment_id', 'together'=>true 
            ),
            'users' => array(
                self::HAS_MANY, 'Users', array('user_id' => 'user_id'), 'through' => 'users_relationships', 'together'=>true 
            ),

        );
    }

And I access it like :

 foreach($model -> users as $value):
    $model-> user_id;
    endforeach;  

Which works fine when I want to access values in the Users model. But when I try to access a value in the EnvironmentUsers model, it throws the notice value cannot be found.

foreach($model -> users as $value):
    $model-> is_environemnt_administrator;
    endforeach;

My question is, how can I also access the the values in the through table when lazy loding in Yii?

tereško
  • 58,060
  • 25
  • 98
  • 150
Devin Dixon
  • 11,553
  • 24
  • 86
  • 167

1 Answers1

1

In your second loop you should call the good related model! It seems you are calling users instead of users_relationships

foreach($model->users_relationships as $value):
    $model-> is_environemnt_administrator;
    endforeach;
darkheir
  • 8,844
  • 6
  • 45
  • 66