Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recovery window option a la acts_as_paranoia #170

Open
wants to merge 10 commits into
base: rails4
Choose a base branch
from

Conversation

wioux
Copy link
Contributor

@wioux wioux commented Oct 2, 2014

This pull request adds a :dependent_recovery_window option to make paranoia compatible with that feature of acts_as_paranoid.

When recovering records recursively, associated records will only be restored if they were deleted within the recovery window timespan of the parent's deletion time. This is to enable recovery of a record's associations as they existed at the time it was destroyed.

The default recovery window is set to 2 minutes for compatibility with acts_as_list.

wioux and others added 7 commits August 27, 2014 16:47
Restoring polymorphic has_one relationships errored because paranoia was
not correctly looking up the foreign_key.

Output from failing test -

ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: parent_model_id: SELECT  "polymorphic_models".* FROM "polymorphic_models" WHERE ("polymorphic_models"."deleted_at" IS NOT NULL) AND (parent_model_id)  ORDER BY "polymorphic_models"."id" ASC LIMIT 1

The test sets up a PolymorphicModel, which has_many parents. The
ParentModel then has a has_one relationship with PolymorphicModel. When
restoring, the foreign key is set as - `self.class.name.to_s.underscore_id`
which will be parent_model_id, instead of the :as option.
If association is a has_one relationship with an :as option, it will
have a type attribute (see https://github.com/rails/docrails/blob/master/activerecord/lib/active_record/reflection.rb).

If it is present, that will be the type column on the polymorphic model.
The foreign key can be found as an attribute on association.
Fix polymorphic has_one relationships
@sudara
Copy link

sudara commented Dec 4, 2014

This should/could/would be merged after #189 — this PR also includes commits from there.

Alternatively we can re-submit a fresh PR after #189 is merged!

Thanks!

@mphalliday
Copy link

It would be great if we could get this merged, now that #189 has been merged.

@bpinto
Copy link

bpinto commented Feb 10, 2015

👍

@bluej100
Copy link
Contributor

This would be very helpful to us.

@bluej100 bluej100 mentioned this pull request Apr 22, 2015
@mkou
Copy link

mkou commented Nov 18, 2015

👍

@bluej100
Copy link
Contributor

In my opinion, this should be used not just for restoration but for queries--if you get the children of a deleted record, then by default, it should show you the records which have the same deletion time as the parent. I agree with @radar that it would considerably expand the scope of this project, but I think it's really what people need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants