I have mounted an uploader in a document with Mongoid::Paranoia included, to prevent hard deletes. But while the document is softly deleted (i.e. has the deleted_at field set), its mounted file is hard deleted. This makes Mongoid::Paranoia useless when combined with Carrierwave.
mount_uploader :media, MyUploader
This is similar to carrierwaveuploader/carrierwave#624. Given the nature of the dependency, I don't think this is something that carrierwave-mongoid (or carrierwave) should be responsible for.
In your document, try something like this:
skip_callback :destroy, :after, :remove_media!
I'm going to take back my original statement for now and instead think about it some more. Upon further review, this is slightly different than carrierwaveuploader/carrierwave#624 because acts_as_paranoid is a third party dependency while Mongoid::Paranoid is built into Mongoid.
Meanwhile, the skip_callback workaround should suffice.
Thanks. I'm overriding remove!() with an empty method in the uploader right now, which seems to work, but it would be nice to not have to work around it.
@rmm5t The skip_callback :destroy, :after, :remove_media! seems to not work...
@ghostganz Hi, could you show how did you work around? Thanks
I'm doing it like this:
class MediaUploader < CarrierWave::Uploader::Base
# no-op override
Thanks, @ghostganz, i'll give a try. Actually I have found this gist too: https://gist.github.com/1596243
Similarly, if I already have a Mongoid document that is deleted (using Mongoid::Paranoia), and then try to upload an attachment with carrierwave and carrierwave-mongoid, the upload is done but the identifier doesn't get written to the document.
It looks like the document's changes array is empty right before save, so the new value doesn't get saved. Still investigating, but have you guys seen this?
Added Mongoid::Paranoia support
Mounted uploaders are kept around if the document is paranoid
Could everyone please confirm that the new paranoia support that was just added resolves the underlying issue?
gem "carrierwave-mongoid", git: "git://github.com/jnicklas/carrierwave-mongoid.git"
I'll release a new official carrierwave-mongoid release soon after.
Just checking back in with everyone on this issue. If I don't hear back from anyone, I'll assume that the code changes attached to this issue resolve everyone's Mongoid::Paranoia problems but might wait for another feature or fix before issuing a new official release. On the other hand, if people would benefit from a new release, I'm glad to do that, but only after getting confirmation that this fully resolves the underlying issue.
I'm stuck on an old version, because of the massive changes needed to go to Mongoid 3, so I won't be able to verify the fix.
I'd be happy if you have a release out by the time we've done the leap to Mongoid 3. :)
@ghostganz I just back ported the paranoia support to the v0.2 line. See carrierwave-mongoid v0.2.2. If any issues, please submit a pull request against the 0.2-stable branch.
Everyone else, there's now a new v0.5.0 release that support Mongoid::Paranoia under Mongoid ~>3.0