simi / mongoid_paranoia

Paranoid Documents for Mongoid 7

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mark soft deleted records as persisted.

simi opened this issue · comments

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?

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

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 :)

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.