active_storage_validations
active_storage_validations copied to clipboard
Presence validation fails to account for marked_for_destruction
Hey, thanks for your work on the gem!
Consider the following example code:
# In model.rb
has_one_attached :image
accepts_nested_attributes_for :image_attachment, allow_destroy: true
validates :image, presence: true
If the image is now set as marked_for_destruction
, via the _destroy
attribute, the image_attachment
is deleted (along with the blob) on saving the model.. This is unexpected, I'm looking for the presence validation to be triggered before any operation is performed with the attachment.
This was a bug in ActiveRecord that has been fixed in Rails 4: https://github.com/rails/rails/pull/6827
Hello @SughoshRao if possible, please create a PR with a fix?
Hi @SughoshRao,
It's been a long time since you raised this issue.
As I understand it while reading your comment + the linked Rails PR, we should not validate with attached: true
(and therefore not delete attachments) if all images
are marked as for destruction.
Am I right?