Mark soft deleted records as persisted.
simi opened this issue · 5 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.
- I think this is the root cause to this cancan issue, #17. "Cancan" was a red herring.
- 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#L109so, 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.