yii\elasticsearch\ActiveRecord::populateRecord PHP Method

populateRecord() public static method

public static populateRecord ( ActiveRecord $record, array $row )
$record ActiveRecord the record to be populated. In most cases this will be an instance created by [[instantiate()]] beforehand.
$row array attribute values (name => value)
    public static function populateRecord($record, $row)
    {
        $attributes = [];
        if (isset($row['_source'])) {
            $attributes = $row['_source'];
        }
        if (isset($row['fields'])) {
            // reset fields in case it is scalar value
            $arrayAttributes = $record->arrayAttributes();
            foreach ($row['fields'] as $key => $value) {
                if (!isset($arrayAttributes[$key]) && count($value) == 1) {
                    $row['fields'][$key] = reset($value);
                }
            }
            $attributes = array_merge($attributes, $row['fields']);
        }
        parent::populateRecord($record, $attributes);
        $pk = static::primaryKey()[0];
        //TODO should always set ID in case of fields are not returned
        if ($pk === '_id') {
            $record->_id = $row['_id'];
        }
        $record->_highlight = isset($row['highlight']) ? $row['highlight'] : null;
        $record->_score = isset($row['_score']) ? $row['_score'] : null;
        $record->_version = isset($row['_version']) ? $row['_version'] : null;
        // TODO version should always be available...
    }