Hi!
Little bit passed beginner stage with Yii I got stuck at this not working. My version is 1.1.15 btw.
Each User model has_one Profile model. And I’m trying to process a limited API call so I want to retrieve a certain set of data from the profile only.
I have the relation defined in User model:
public function relations()
{
$relations = Yii::app()->getModule('user')->relations;
if (!isset($relations['profile']))
$relations['profile'] = array(self::HAS_ONE, 'Profile', 'user_id');
return $relations;
}
Then I have the following scope set in Profile model:
public function scopes()
{
return array(
'api' => array(
'select' => 'photoURL, displayName',
),
);
}
And finally in my ApiController I call upon this the following way:
$data = User::model()->with('profile:api')->findByPk(Yii::app()->user->id);
This actually works. But the problem is the scope is not applied to the Profile pulled in. I still have all the other columns as well. Some documentation/forums said the other columns will be returned with "null’ values but it’s not even that, they’re all filled out properly and I don’t want to return all information to the API (due to security reasons as well).
Can you please advise why this is not working for me? I found two more posts with no answers.