Yii 1.1.6
PHP 5.3
Есть модели User и Profile.
Код: Выделить всё
public function relations() {
return array(
'profile' => array(self::HAS_ONE, 'Profile', 'user_id'),
);
}
Код: Выделить всё
$criteria = new CDbCriteria();
$criteria->with = array('profile');
$models = User::model()->findAll($criteria);
Код: Выделить всё
$dataProvider = new CArrayDataProvider($models, array(
'keyField' => 'id',
'sort' => array(
'attributes' => array(
'name' => array(
'asc'=>'profile.user_name',
'desc'=>'profile.user_name DESC',
'label' => Yii::t('UserModule.frontend', 'Name')
),
),
),
));
Причем без сортировки все эти поля отображаются(ну т.е. $data->profile->user_name), сортировка по полям модели User также работает нормальноProperty "User.profile.user_name" is not defined.
/home/rak/Work/localhost/root/htdocs/framework/db/ar/CActiveRecord.php(110)
Stack Trace
#0
– /home/rak/Work/localhost/root/htdocs/framework/db/ar/CActiveRecord.php(110): CComponent->__get("profile.user_name")
105 else if(isset($this->_related[$name]))
106 return $this->_related[$name];
107 else if(isset($this->getMetaData()->relations[$name]))
108 return $this->getRelated($name);
109 else
110 return parent::__get($name);
111 }
112
113 /**
114 * PHP setter magic method.
115 * This method is overridden so that AR attributes can be accessed like properties.
#1
– //home/rak/Work/localhost/root/htdocs/framework/web/CArrayDataProvider.php(118): CActiveRecord->__get("profile.user_name")
113 $dummy=array();
114 foreach($directions as $name=>$descending)
115 {
116 $column=array();
117 foreach($this->rawData as $index=>$data)
118 $column[$index]=is_object($data) ? $data->$name : $data[$name];
119 $args[]=&$column;
120 $dummy[]=&$column;
121 unset($column);
122 $direction=$descending ? SORT_DESC : SORT_ASC;
123 $args[]=&$direction;