-
Notifications
You must be signed in to change notification settings - Fork 20
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
dependent: :destroy
option on association destroys models related to source after cloning
#29
Comments
I had debugged the issue a little bit and here is what I found: This line is destroying association on source model:
Problem is that
|
After a fresh look, I've realized what's going on:
So when the cloning process starts,
It would be great to check if an association has |
Hi @dolhishev! Your case is interesting and unusual but make sense, yeh. class UUIDActiveRecordAdapter < Clowne::Adapters::ActiveRecord
class << self
def dup_record(record)
super.tap do |clone|
clone.uuid = nil
end
end
end
end
# and
class BaseCloner < Clowne::Cloner
adapter UUIDActiveRecordAdapter
end
class SomeModelCloner < BaseCloner
# declarations
end
Hm, maybe is too rude to raise an exception but we can handle this case and put a warning message. I'll think about it. |
Associations that contain
dependent: :destroy
option will be destroyed on source object after the cloning process. It's easy to reproduce in your tests - just adddependent: :destroy
tohas_one :image, class_name: 'AR::Image'
and tests will fail.The text was updated successfully, but these errors were encountered: