lib/avo/base_resource.rb in avo-2.36.1 vs lib/avo/base_resource.rb in avo-2.36.2
- old
+ new
@@ -375,15 +375,13 @@
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])
# set the value to the actual record
@@ -396,20 +394,18 @@
value = model.send(id_param)
end
end
- [id, value]
+ [field, value]
end
.to_h
- .select do |id, value|
+ .select do |_, value|
value.present?
end
- default_values.each do |id, value|
- if @model.send(id).nil?
- @model.send("#{id}=", value)
- end
+ default_values.each do |field, value|
+ field.assign_value record: @model, value: value
end
end
def route_key
class_name_without_resource.underscore.pluralize