Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid override of previously assigned attributes #364

Open
chinshr opened this issue Jul 15, 2016 · 0 comments
Open

Avoid override of previously assigned attributes #364

chinshr opened this issue Jul 15, 2016 · 0 comments

Comments

@chinshr
Copy link

chinshr commented Jul 15, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant