Skip to content

using CheckboxRelationActiveQuery and sortRelationModel can add data but not displayed on listing #257

Open
@mrtrinhvn

Description

@mrtrinhvn

I have model Huyet and Nhomuyet. Huyet has a property gorup_ids which store the ids of the Nhomuyet. (mean group of Huyet).
When I add a new Huyet or edit a Huyet, the window displays the checkbox with the 'ten' of Nhom huyet as expected. But when listing Huyet, Nhom huyet shown as open and close square bracket [] (if i use CheckboxRelationActiveQuery), or as [{"value":2,"label":"Block"},{"value":1,"label":"Heatting"}]. (if i use sortRelationModel).
So, how to display 'ten' of Nhomhuyet is display, more effective i can click to show the Nhomhuyet?
public function ngRestAttributeTypes()
{
return [
////using sortRelationModel
// 'group_ids' => [
// 'sortRelationModel',
// 'modelClass' => Nhomhuyet::className(),
// 'valueField' => 'id',
// 'labelField' => 'ten'
// ],
////using CheckboxRelationActiveQuery
'group_ids' => [
'class' => CheckboxRelationActiveQuery::class,
'query' => $this->getGroups(),
'labelField' => ['ten'],
],
'hinh' => 'image',
'ten' => 'text',
];
}

public function getGroups()
{
return $this->hasMany(Nhomhuyet::class, ['id' => 'nhomhuyet_id'])->viaTable(HuyetToNhom::tableName(), ['huyet_id' => 'id']);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions