yii“在view.php上尝试获取非对象的属性”

I have a strange problem with my yii application. I have two tables in my database Players - id, name, team_id and Teams - id, name. I can create new players but when I want to see player's profile there is an error -"Trying to get property of non-object" at this line:

'value'=>$model->team->NAME,

The most strange problem is that when I test url for players with Ids 1 and 2 everything is okay and I see the correct information, but for other ids I have this problem. Here is part of my code:

view.php

<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
    'ID',
    'NAME',
    'TEAM_ID', 
    array(
        'label'=>'Отбор',
        'type'=>'text',
        'value'=>$model->team->NAME,
    ),
),
)); ?>

Players.php

public function relations()
    return array(
      'team' => array(self::BELONGS_TO, 'TEAMS', 'ID'),
    );
}

Teams.php

public function relations()
{
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
    return array(
        'player' => array(self::HAS_MANY, 'PLAYERS', 'ID'),
    );
}

PlayersController.php

public function actionView($id)
{
    $teams = new CActiveDataProvider('Teams');
    $players = new CActiveDataProvider('Players');
    $this->render('view', array(
        'model'=>$this->loadModel($id),
    ));
}

Seems like you need to fix bug with relations in Players model:

public function relations()
    return array(
      'team' => array(self::BELONGS_TO, 'TEAMS', 'TEAM_ID'), // TEAM_ID instead of ID
    );
}