'Yii2: How to save/update field with integer array data type

I am trying to save a record with a field of integer array int[] data type to pgsql table but am unable to set the value in that field.

My save code is as follows:

$record = $this->findModel($modifiedRecord[$this->_idField]);
    
if($record){
    try{
        if($record->load($modifiedRecord,'') && $record->save()){
            $response=[
            'success'=>TRUE,
            'message'=>'Record Saved Successfully.',
            ];
        }
        else{
            $response=[
            'success'=> FALSE,
            'message'=>'Record Save Failed.',
            'errors' => $record->getErrors()
            ];
        }
    }catch(Exception $e){
    }
}

When I tried to view the data being passed and the model attribute after save with following code: enter image description here

The output is as follows:

1) Update Attributes: 

array (size=6)
  'view_role' => string '{1,10,50}' (length=9)
  'id' => string '12568' (length=5)
  'updated_datetime' => string '2022-04-26 15:52:26' (length=19)
  'updated_by' => int 1


2) After load to model:
array (size=23)
  'id' => int 12568
  .
  .
  .
  'view_role' => string '{1,10,50}' (length=9)
  .
  .
  .


3) After save success:
  'id' => int 12568
  .
  .
  .
  'view_role' => string '{1,10,50}' (length=9)
  .
  .
  .

Even though the model save result showed that the value was updated, the view_role field in the table was reset to {}. enter image description here

Can anybody tell me how to fix this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source