Hi All,
I have the following model with relations:
class Testone extends ActiveRecord {
public $testtwo;
public function getTestwo() {
return $this->hasOne(Testtwo::className(), ['id' => 'id_test']);
}
public function rules() {
return [[['atr1', 'atr2', 'testtwo'], 'safe']];
}
public function search($params) {
$query = Testone::find();
$query->joinWith(['testtwo']);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 10,
],
]);
// walidacja parametrów wyszukiwania
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(['like', '{{%testtwo}}.value', $this->testtwo]);
return $dataProvider;
}
I display related column in the component Krajee DataGrid:
$relatedColumns = [[
'attribute' => 'testtwo',
'value' => 'testtwo.value',
'class' => DataColumn::className(),
]];
Here there is a problem. Filter for the ‘testtwo’ column works properly. But I do not know why the cell’s value is always “(not set)”. When I change the ‘testtwo’ variable type (from public to protected) the data set properly but filter’s value is lost after ajax reloading.
public $testtwo;
// filter's field works properly but data is not set
protected $testtwo;
// filter's field lose the value after reloading but data is set
What am I doing wrong? Please, help.
Thank you in advance.
PS. Sory for my english