Skip to content

Commit

Permalink
Use object attribute if it exists for parents
Browse files Browse the repository at this point in the history
  • Loading branch information
eni9889 authored Aug 10, 2022
1 parent 6992c91 commit a160cb0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/inputs/nested_select_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def set_parent_value(level_data)
parent_attribute = level_data[:parent_attribute]
build_virtual_attr(parent_attribute)
instance = instance_from_attribute_name(level_data[:attribute])
if instance&.respond_to?(parent_attribute)
if @object&.respond_to?(parent_attribute) && @object.send(parent_attribute).present?
# do nothing
elsif instance&.respond_to?(parent_attribute)
@object.send("#{parent_attribute}=", instance.send(parent_attribute))
end
end
Expand Down

0 comments on commit a160cb0

Please sign in to comment.