simi/mongoid_paranoia

Mark soft deleted records as persisted.

simi opened this issue · 5 comments

simi commented

I had a lot of issues today with this flag. CarrierWave photos were deleted and embeded models returned persisted? #=> false and to_param => nil, which caused a lot of issued in rails url helpers.

I started work in persistence branch.

Anyone against this change?

simi commented

Merged in ea986ac.

I see a side effect here.

  1. I think this is the root cause to this cancan issue, #17. "Cancan" was a red herring.
  2. The real issue is using the "respond_with @deleted_model" syntax in one's controller. The expected behavior is a redirect to the "index" action. This change breaks that behavior and now respond_with redirects to the "show" action resulting in the "document not found" error.

See: mongoid/mongoid@34e895ab
Notice that Mongoid explicitly returns persisted=false when destroyed. The reason for the change is documented here: https://groups.google.com/d/msg/mongoid/RBb2Se511sc/xKqi7tf90SMJ.

The explanation provided by visnup:

AR marks a destroyed record as !persisted? and polymorphic routes pick up on that:
https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb#L109

so, the fix would be to make sure that persisted? in mongoid returns false for destroyed objects

simi commented

This was merged because of mongoid internal changes. I'll take a look what changed, but without this, there were some issues.

This should really be reverted imho, because it can and will break existing apps using mongoid-paranoia when mongoid 4.0.0 is released.

@simi You should fix your problems in your specific app, I can help you :)

simi commented

Revert = red CI. Feel free to revert and make it green. I have not changed tests except one. If i remember well, this test will not pass 11ddc35. I'm around to help you. IRC Freenode, name retro|cz.