I am trying to join two tables together and get the phone number username of a user, when the oncallduty true is.
public function actionGetPhone($name) {
$userHasTeam = new UserHasTeam();
$criteria = new CDbCriteria();
$criteria->with = array('teams', $userHasTeam);
$criteria->together = true;
$criteria->addCondition($userHasTeam->oncallduty = 1);
$model = User::model()->find($criteria);
Yii::log(print_r($model, true));
echo $model['username'];
echo $model['mobile'];
}
This is what I have so far. All this is packed in a function that can be called through a GET request.
I have found the solution. I don't know exactly why, but a model that I tried to connect to somehow got an alias. To that end I could not connect to the table at all. Below the way I did it.
$criteria = new CDbCriteria();
$criteria->with = array('teams');
$criteria->addCondition('teams.name = :teams');
$criteria->addCondition('teams_teams.oncallduty = 1');
$criteria->params = array(':teams'=>$name);
$model = User::model()->find($criteria);
echo "This is the mobile of user on duty: ".$model['mobile'];