class Avo::BaseResource

def hydrate_model_with_default_values

We will not overwrite any attributes that come pre-filled in the model.
def hydrate_model_with_default_values
  default_values = get_fields
    .select do |field|
      !field.computed
    end
    .map do |field|
      id = field.id
      value = field.value
      if field.type == "belongs_to"
        id = field.foreign_key.to_sym
        reflection = @model._reflections[@params[:via_relation]]
        if field.polymorphic_as.present? && field.types.map(&:to_s).include?(@params["via_relation_class"])
          value = @params["via_relation_class"].safe_constantize.find(@params[:via_resource_id])
        elsif reflection.present? && reflection.foreign_key.present? && field.id.to_s == @params[:via_relation].to_s
          value = @params[:via_resource_id]
        end
      end
      [id, value]
    end
    .to_h
    .select do |id, value|
      value.present?
    end
  default_values.each do |id, value|
    if @model.send(id).nil?
      @model.send("#{id}=", value)
    end
  end
end