I have two tables with design master detail.
The master table is named Format2006FlatFileMaster.
The detail table is named Format2006FlatFileDetail.
My goal is, I want to use a field as key and the value is their child of master.
I mean like this
$details = ArrayHelper::map(Format2006FlatFileMaster::find()->all(), 'alias', function ($model) {
$model->format2006FlatFileDetails;
});
I got like this data, (For ex, this is dummy data)
'details' => [
'HDR01' => [
0 => app\models\utilities\Format2006FlatFileDetail#1
(
[yii\db\BaseActiveRecord:_attributes] => [
'id' => 1
'2006_flat_file_master_id' => 1
'field_name' => 'Record Lable'
'start' => 1
'width' => 5
'decimal' => null
'type' => 'C'
'mandatory' => 'Y'
'note' => 'HDR01'
]
[yii\db\BaseActiveRecord:_oldAttributes] => [
'id' => 1
'2006_flat_file_master_id' => 1
'field_name' => 'Record Lable'
'start' => 1
'width' => 5
'decimal' => null
'type' => 'C'
'mandatory' => 'Y'
'note' => 'HDR01'
]
[yii\db\BaseActiveRecord:_related] => []
[yii\db\BaseActiveRecord:_relationsDependencies] => []
[yii\base\Model:_errors] => null
[yii\base\Model:_validators] => null
[yii\base\Model:_scenario] => 'default'
[yii\base\Component:_events] => []
[yii\base\Component:_eventWildcards] => []
[yii\base\Component:_behaviors] => []
)
1 => app\models\utilities\Format2006FlatFileDetail#2
(
[yii\db\BaseActiveRecord:_attributes] => [
'id' => 2
'2006_flat_file_master_id' => 1
'field_name' => 'Message Function Code'
'start' => 6
'width' => 1
'decimal' => null
'type' => ''
'mandatory' => 'Y'
'note' => '1 Original 2 Update (handle manually) 3 Consolidation (handle manually)'
]
[yii\db\BaseActiveRecord:_oldAttributes] => [
'id' => 2
'2006_flat_file_master_id' => 1
'field_name' => 'Message Function Code'
'start' => 6
'width' => 1
'decimal' => null
'type' => ''
'mandatory' => 'Y'
'note' => '1 Original 2 Update (handle manually) 3 Consolidation (handle manually)'
]
[yii\db\BaseActiveRecord:_related] => []
[yii\db\BaseActiveRecord:_relationsDependencies] => []
[yii\base\Model:_errors] => null
[yii\base\Model:_validators] => null
[yii\base\Model:_scenario] => 'default'
[yii\base\Component:_events] => []
[yii\base\Component:_eventWildcards] => []
[yii\base\Component:_behaviors] => []
)
]
]
As you can see, the data on the third parameter is in array objects, I need in array format like this.
'details' => [
'HDR01' => [
0 => [
'id' => 1
'2006_flat_file_master_id' => 1
'field_name' => 'Record Lable'
'start' => 1
'width' => 5
'decimal' => null
'type' => 'C'
'mandatory' => 'Y'
'note' => 'HDR01'
],
1 => [
'id' => 2
'2006_flat_file_master_id' => 1
'field_name' => 'Message Function Code'
'start' => 6
'width' => 1
'decimal' => null
'type' => ''
'mandatory' => 'Y'
'note' => '1 Original 2 Update (handle manually) 3 Consolidation (handle manually)'
]
]
]
Please Advise.