moiristo / deep_cloneable

This gem gives every ActiveRecord::Base object the possibility to do a deep clone that includes user specified associations.
MIT License
786 stars 88 forks source link

Not possible to exclude attribute named 'rank' #147

Closed handzlikt closed 1 year ago

handzlikt commented 1 year ago

I have a model that has a 'rank' attribute and I want to exclude it from cloning: original.deep_clone except: :rank. But it's still keeping the original rank. It happens on Rails 5.2 with Ruby 2.5 and deep_cloneable 3.2

moiristo commented 1 year ago

When an exception is applied, it assigns the default database value (else nil) to the attribute. I don't see how that could go wrong. It is tested in https://github.com/moiristo/deep_cloneable/blob/master/test/test_deep_cloneable.rb#L15, so I'm assuming for now that something else in your code is preventing the reassignment. If you think that's not the case, I really need a failing test case to be able to reproduce the issue.

handzlikt commented 1 year ago

Thank you for your response. When trying to prepare the test case I realised there was is a default value applied on that field in our database... Sorry for taking your time.