Questions tagged [ruby-paranoia]

Paranoia is a re-implementation of the `acts_as_paranoid` plugin that uses much less code. It works for Rails 3 and Rails 4.

Paranoia is a re-implementation of acts_as_paranoid for Rails 3 and Rails 4, using much, much, much less code.

You would use either plugin / gem if you wished that when you called destroy on an Active Record object that it didn't actually destroy it, but just hide the record. Paranoia does this by setting a deleted_at field to the current time when you destroy a record, and hides it by scoping all queries on your model to only include records which do not have a deleted_at field.

If you wish to actually destroy an object you may call really_destroy!.

WARNING: This will also really destroy all dependent: :destroy records, so please aim this method away from face when using.

If a record has has_many associations defined AND those associations have dependent: :destroy set on them, then they will also be soft-deleted if acts_as_paranoid is set, otherwise the normal destroy will be called.

More about Paranoia at github

29 questions
6
votes
6 answers

Paranoia Gem - joins with deleted items

I'm using Paranoia gem and now struggling with the problem. I need to joins has_many deleted items, but it returns not deleted only. My models: class Mailing < ActiveRecord::Base acts_as_paranoid has_many :mailing_fields has_many :fields,…
Pavel
  • 1,934
  • 3
  • 30
  • 49
5
votes
4 answers

Unique constraint issue paranoia gem

I have a rails app in which i am using devise and paranoia gems. I have a users table in postgres db which has unique validation on email column. I am using paranoia for soft delete, issue is when i delete a user and then tey to create a user…
2
votes
1 answer

Rails using Paranoia and Administrate, Is there a way to get deleted record with administrate for user?

I would like to get all deleted records change by paranoia on admin panel with administrate. My problem is that I'm finding a way to do this stuff but until now without success Actually what I'm trying to do is to override index method on a specific…
Snoobie
  • 760
  • 2
  • 12
  • 30
2
votes
1 answer

Paranoia in recursive restore

I'm using the paranoia / acts_as_paranoid gem to soft delete my models. I have a 1 to many relationship between posts and comments. They are both paranoid and on destroy everything works as expected. My relationships are set up like…
2
votes
3 answers

Need to return the :name of an object, even if it was soft deleted (using paranoia)

I have Users in the system which can be soft_deleted using paranoia (2.0.2) and TimeRecords which keep track of how many :hours a user worked on a given assignment and what their total :cost was for the entire assignment (:cost = :rate * :hours to…
1
vote
2 answers

active admin paranoia gem can't work with friendly id gem?

I'm working on a Rails 6 app and have a blog model with a slug generated by FriendlyId gem. I added Active admin and I had to add this code to config/initializers/active_admin.rb to make it work properly and search by the id and not the slug. …
sara lance
  • 493
  • 4
  • 16
1
vote
0 answers

Calling a soft-deleted object to really_destroy with paranoid gem

I have a list of Accounts that get called throught the paranoid gem this in the accounts_controller: @deleted_accounts_count = Account.only_deleted.count, or @deleted_accounts = Account.only_deleted.paginate( total_entries:…
1
vote
0 answers

Rails - Shared entry between 2 Users - Soft deletion for each user independently

I have a Rails 5 app with 2 models : User & Application User can apply to another User through Application model When an Application is created by User 1 to User 2, both users can see it inside their Application#index view. Each User can delete an…
Mene
  • 344
  • 2
  • 14
1
vote
1 answer

Multi-column index vs seperate indexes vs partial indexes

While working on my Rails app today I noticed that the paranoia gem says that indexes should be updated to add the deleted_at IS NOT NULL as a where on the index creation (github link). But It occurred to me that the inverted condition when I do…
Ash
  • 24,276
  • 34
  • 107
  • 152
1
vote
1 answer

"Create" not working with ruby paranoia on heroku

I've implemented paranoia on a model ("Stays"), which is working in development, but not in production on heroku. On the heroku site, I can see an (expectedly empty) index page, but when I go to /stays/new, I get an error page. Checking the logs, I…
Derrick
  • 13
  • 2
1
vote
2 answers

Using acts_as_paranoid with DelayedJob?

Can someone tell me precisely how to integrate acts_as_paranoid with DelayedJob? I've tried creating a class Delayed::Backend::ActiveRecord::Job and adding acts_as_paranoid to it but even if I use an initializer and require the new class,…
Paul D Smith
  • 639
  • 5
  • 16
1
vote
1 answer

Rails 5 compatibility between Paranoia and CanCanCan, compromised?

I'm having the exact same issue as described on this thread: Rails 5 only_deleted with cancancan #356 I can access a deleted record, like this: @area = Area.only_deleted.find(params[:id]) but if I add load_and_authorize_resource to my…
1
vote
2 answers

Rails 5 Paranoia - How can I 'show' a deleted record?

Upon soft-deleting a record, I'm unable to call it on the show action on the controller, for it looks for a record matching the record's ID WHERE deleted_at IS NULLL, which is correct given the purpose of the gem, but I'd still like to be able to…
1
vote
1 answer

Rails association with_deleted scope doesn't work with order

Here is what I got so far : class MemberSitePosition < ActiveRecord::Base acts_as_paranoid belongs_to :member, -> { with_deleted } belongs_to :position ... } class Member < ActiveRecord::Base include ::Hierarchical acts_as_paranoid …
Incognito
  • 493
  • 2
  • 8
  • 22
0
votes
0 answers

Can I recreate an object after really_destroy! it ? I do not want to recover it but create a new object with same email

I am using paranoia 2.4.2. I have used really_detroy! to "really destroy" a user. Now I am failing with recreate it in my database. I did: Student.create(email: "blabla@bla.com", profile: 342) Error message is: Student Exists (8.2ms) SELECT 1 AS…
Bruno Toledo
  • 87
  • 1
  • 9
1
2