I am having an issue to assign nested attributes avoiding to override previous ones. Here is an example:
class Product
include Virtus.model
attribute :values, Values
end
class Values
include Virtus.model
attributes :name
attributes :description
end
Now let's say we want to assign attribute of values in two separate assigns:
product = Product.new
product.values = {name: "a product"}
product.values.name # => "a product"
product.values.description # => nil
# now assign description
product.values = {description: "a description"}
product.values.description # => "a description"
product.values.name # => nil, I don't want name to be nil
Can anyone show me a way how to solve this problem without overriding the elements, considering, there could potentially be deeper nested structures.
I am having an issue to assign nested attributes avoiding to override previous ones. Here is an example:
Now let's say we want to assign attribute of
values
in two separate assigns:Can anyone show me a way how to solve this problem without overriding the elements, considering, there could potentially be deeper nested structures.