Coder Social home page Coder Social logo

acts_as_paranoid's People

Contributors

aake avatar alexwheeler avatar avinoth avatar aymeric-ledorze avatar cheerfulstoic avatar chuckg avatar cloudsbird avatar copyhacker avatar danielricecodes avatar dependabot[bot] avatar donv avatar dra1n avatar filiptepper avatar flah00 avatar goncalossilva avatar h0jezvgoxfepbq2c avatar mvz avatar nedcampion avatar nu-hin avatar overbryd avatar pauldruziak avatar pelargir avatar pyromaniackeca avatar rasaffie avatar reinaris avatar ri4a avatar romainalexandre avatar sjke avatar softcraft-development avatar taelor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

acts_as_paranoid's Issues

destroy! doesn't set @destroyed-Attribute

Original ActiveRecord-Behaviour:
record.destroy
record.deleted? => true

With acts_as_paranoid
record.destroy
record.deleted? => false

but
record.destroy
record.reload
record.deleted? => true

acts_as_paranoid will update the deleted_at flag without setting it to the object, so deleted? won't know, that the object was deleted. Since you call freeze, I think, deleted? should return true instantly

Using with public_activity gem

I am using https://github.com/pokonski/public_activity on a number of models that I am protecting with acts_as_paranoid. Right now when an associated record that is tracked is destroyed, it cannot be viewed in rendered activities because the polymorphic association checks for records that are not deleted, which is standard behavior with the gem. I would like, however, to be able to override this behavior so that deleted records are included in the association.

I tried something like this:

class IdeaHistory < ActiveRecord::Base
    include PublicActivity::Renderable

    self.table_name = PublicActivity.config.table_name

    acts_as_paranoid

    # Define polymorphic association to the parent
    belongs_to :trackable, :polymorphic => true
    # Define ownership to a resource responsible for this activity
    belongs_to :owner, :polymorphic => true
    # Define ownership to a resource targeted by this activity
    belongs_to :recipient, :polymorphic => true, with_deleted: true
    belongs_to :recipient_including_deleted, :class_name => "Idea", :foreign_key => 'recipient_id', :with_deleted => true
    # Serialize parameters Hash
    serialize :parameters, Hash

    if ::ActiveRecord::VERSION::MAJOR < 4 || defined?(ProtectedAttributes)
      attr_accessible :key, :owner, :parameters, :recipient, :trackable
    end
end

where I hard coded the recipient to be one of my models but it did not work. Do you have any idea how I can get public_activity and acts_as_paranoid to work well together?

can't modify frozen hash with accepts_nested_attributes_for delete

When used with accepts_nested_attributes_for with a has_many association, only when using :allow_destroy for accepts_nested_attributes_for, the associated class which acts_as_paranoid gives this error.

can't modify frozen hash
/home/buddhika/www/payments_staging/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:313:in []=' /home/buddhika/www/payments_staging/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:313:inwrite_attribute_without_dirty'
/home/buddhika/www/payments_staging/vendor/rails/activerecord/lib/active_record/dirty.rb:139:in write_attribute' /home/buddhika/www/payments_staging/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:216:indeleted_at='
/home/buddhika/www/payments_staging/vendor/plugins/acts_as_paranoid/lib/caboose/acts/paranoid.rb:172:in `destroy_without_callbacks'

Support for recover!

currently on recover method, it fails silently returning false when the validations for the model fails, similar to create or update. It would be nice to have a support for recover! method which raises an exception on validation fails.

I'm currently doing this by overriding recover in my model but it would be nice to have a support for this. I can create a PR for this if okay.

Wrong SQL generated for with_deleted

Hello, at Litmus we have two classes Account and User in a "1 to n" relationship.
We use acts_as_paranoid in both the classes.

We're upgrading to Rails 4.2, and we noticed this wrong generated SQL.

[2] pry(main)> account.users.with_deleted.to_sql
=> "SELECT `users`.* FROM `users`"

The expected query is:

[2] pry(main)> account.users.with_deleted.to_sql
=> "SELECT `users`.* FROM `users` WHERE `users`.`account_id` = 1"

This is already solved by #26 Can you please merge it? ๐Ÿ’™ ๐Ÿ’š โค๏ธ ๐Ÿ’› โค๏ธ Thank you!

Feature: Remove condition for joins.

It would be awesome if you would add ability to unscope joins or let unscoped affect joined associations as well.

Now there is no way to include deleted associations into joined conditions. It always adds something like "rabbits"."deleted_at" IS NULL to the FROM carrots INNER JOIN rabbits ON rabbits.id = carrots.rabbit_id.

delete_all does real deletion

Hi, I have an issue about delete_all in transaction.
Here is a piece of my code

MyModel.transaction do
   MyModel.delete_all(region: 'xxx')
   ...
end

And I found that it generates a SQL of

DELETE
FROM `my_models`
WHERE `my_models`.`deleted_at` IS NULL AND `my_models`.`region` = 'xxx'

The expectation should be

UPDATE `my_models`
WHERE `my_models`.`deleted_at` IS NULL AND `my_models`.`region` = 'xxx'
SET `my_models`.`deleted_at` = Now

Is this a bug or is there any issue in my code?
Thanks.

Conflict with ActiveRecord destroyed? method

ActiveRecord to have method name destroyed? (http://apidock.com/rails/ActiveRecord/Persistence/destroyed%3F). Can't we avoid alias_method :destroyed?, :deleted?.

Due to overriding of destroyed? method by the gem we cannot use update_column or update_columns method on records which are soft deleted. (http://apidock.com/rails/ActiveRecord/Persistence/update_columns)

This line throws exception raise ActiveRecordError, "cannot update a destroyed record" if destroyed? while using update_columns.

Is it intentional?

deleted_at column should be mass-assignable

Hi!

acts_as_paranoid 0.4.2 made the "deleted_at" column not mass_assignable. We depend on it being mass-assignable, and we think it should be treated as a regular attribute.

Could you revert the change?

If you cannot revert the change, could you make this behaviour optional?

Thanks for a very useful gem.

Associations not working in production mode

I have got a problem with acts_as_paranoid and associations in production mode (development works fine).

class User
  acts_as_paranoid
  has_many :activities, :as => :owner, :dependent => :destroy
end

class Activity
  acts_as_paranoid
  belongs_to :owner, :polymorphic => true
end

When I call Activity.destroy(x), everything workes fine. But when I want to destroy the User (and the activities with it), I get an * TypeError: can't modify frozen hash* error. I do have some equivalent associations and always get an error, when I want to destroy an object, with associatiated paranoid elements.

In development mode everythings works fine!
I'm using Rails 2.3.2 and the latest acts_as_paranoid version.

validates_uniqueness_of_without_deleted :column fails for serialized columns

Rails 4.2.3
Ruby 2.3.0p0
Linux x86-64

class Foo < ActiveRecord::Base
  acts_as_paranoid
  validates_as_paranoid
  serialize :colors, Array

  validates_uniqueness_of_without_deleted :colors
end

This raises the exception ActiveRecord::SerializationTypeMismatch: Attribute was supposed to be an Array, but was a String. when calling @foo.update_attributes with a new colors array.

Are serialized fields supported by validates_uniqueness_of_without_deleted?

Not working inside rails engine.

I am using acts_as_paranoid gem inside a rails engine. gem is added as add_dependency in .gemspec file. But I am getting error NameError: undefined local variable or method `acts_as_paranoid' until unless I am specifying gem in Gemfile of the app where I am using that engine.

alias_method_chain is deprecated. Please, use Module#prepend instead

Hi

Please check below WARNING when I am using command line interface .

DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from singleton class at /home/daffolap-244/.rvm/gems/ruby-2.3.0@diary/gems/acts_as_paranoid-0.5.0/lib/acts_as_paranoid/associations.rb:6)
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from block in included at /home/daffolap-244/.rvm/gems/ruby-2.3.0@diary/gems/acts_as_paranoid-0.5.0/lib/acts_as_paranoid/preloader_association.rb:11)

NameError: undefined method `validate_find_options' for class `Class'

I have just integrated the gem into the Gemfile of my Rails 4.2.4 Application, and this is what i got when trying to restart the development server. Is this a compatibility issue?

Stacktrace:

Uncaught exception: undefined method `validate_find_options' for class `Class'
    /Users/moritzkroger/Documents/dev/megatron/vendor/ruby/2.2.0/gems/acts_as_paranoid-0.3.1/lib/acts_as_paranoid.rb:42:in `alias_method'
    /Users/moritzkroger/Documents/dev/megatron/vendor/ruby/2.2.0/gems/acts_as_paranoid-0.3.1/lib/acts_as_paranoid.rb:42:in `singleton class'
    /Users/moritzkroger/Documents/dev/megatron/vendor/ruby/2.2.0/gems/acts_as_paranoid-0.3.1/lib/acts_as_paranoid.rb:41:in `included'
    /Users/moritzkroger/Documents/dev/megatron/vendor/ruby/2.2.0/gems/acts_as_paranoid-0.3.1/lib/acts_as_paranoid.rb:166:in `include'
    /Users/moritzkroger/Documents/dev/megatron/vendor/ruby/2.2.0/gems/acts_as_paranoid-0.3.1/lib/acts_as_paranoid.rb:166:in `<top (required)>'
    /Users/moritzkroger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `require'
    /Users/moritzkroger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
    /Users/moritzkroger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in `each'
    /Users/moritzkroger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in `block in require'
    /Users/moritzkroger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `each'
    /Users/moritzkroger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `require'
    /Users/moritzkroger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler.rb:134:in `require'
    /Users/moritzkroger/Documents/dev/megatron/config/application.rb:7:in `<top (required)>'
    /Users/moritzkroger/Documents/dev/megatron/vendor/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:78:in `require'
    /Users/moritzkroger/Documents/dev/megatron/vendor/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:78:in `block in server'
    /Users/moritzkroger/Documents/dev/megatron/vendor/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap'
    /Users/moritzkroger/Documents/dev/megatron/vendor/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server'
    /Users/moritzkroger/Documents/dev/megatron/vendor/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    /Users/moritzkroger/Documents/dev/megatron/vendor/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
    /Users/moritzkroger/Documents/dev/megatron/bin/rails:4:in `require'
    /Users/moritzkroger/Documents/dev/megatron/bin/rails:4:in `<top (required)>'

I'm getting a Multiple Assignment error?

So, I have 3 tables Accounts, Users, and Subscriptions all of which have the deleted_at column. Now when I delete an account the request gets sent to all models at once causing a Multiple Assignments error as shown below:

Started DELETE "/admin/accounts/3" for 127.0.0.1 at 2014-10-27 19:38:48 +0200
Processing by SaasAdmin::AccountsController#destroy as HTML
  Parameters: {"authenticity_token"=>"qo8NxYhezJUz2YylGxHlx2ou125UNoRuEcXbrnzyiN4=", "id"=>"3"}
  AppSetting Load (0.3ms)  SELECT "app_settings".* FROM "app_settings" ORDER BY "app_settings"."id" ASC LIMIT 1
  Tag Load (0.2ms)  SELECT "tags".* FROM "tags" WHERE "tags"."id" = $1 LIMIT 1  [["id", 22]]
  SaasAdmin Load (0.2ms)  SELECT "saas_admins".* FROM "saas_admins" WHERE "saas_admins"."id" = 4 ORDER BY "saas_admins"."id" ASC LIMIT 1
  Account Load (0.1ms)  SELECT "accounts".* FROM "accounts" WHERE (accounts.deleted_at IS NULL) AND "accounts"."id" = $1 LIMIT 1  [["id", "3"]]
   (0.1ms)  BEGIN
  Subscription Load (0.3ms)  SELECT "subscriptions".* FROM "subscriptions" WHERE (subscriptions.deleted_at IS NULL) AND "subscriptions"."subscriber_id" = $1 AND "subscriptions"."subscriber_type" = $2 LIMIT 1  [["subscriber_id", 3], ["subscriber_type", "Account"]]
  SQL (0.3ms)  UPDATE "subscriptions" SET deleted_at = '2014-10-27 17:38:48.909001', deleted_at = '2014-10-27 17:38:48.909025' WHERE (subscriptions.deleted_at IS NULL) AND "subscriptions"."id" = 3
PG::SyntaxError: ERROR:  multiple assignments to same column "deleted_at"
: UPDATE "subscriptions" SET deleted_at = '2014-10-27 17:38:48.909001', deleted_at = '2014-10-27 17:38:48.909025' WHERE (subscriptions.deleted_at IS NULL) AND "subscriptions"."id" = 3
   (0.1ms)  ROLLBACK
Completed 500 Internal Server Error in 7ms

 ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR:  multiple assignments to same column "deleted_at"
: UPDATE "subscriptions" SET deleted_at = '2014-10-27 17:38:48.909001', deleted_at = '2014-10-27 17:38:48.909025' WHERE (subscriptions.deleted_at IS NULL) AND "subscriptions"."id" = 3):
  activerecord (4.0.4) lib/active_record/connection_adapters/postgresql_adapter.rb:791:in `async_exec'

What can we do to fix this?

See the full logs below by visiting the Gist link: https://gist.github.com/rmagnum2002/2358536587bb34dbbc52

validates_uniqueness_of_without_deleted doesnt validate

I have an issue with validates_uniqueness_of_without_deleted, it doesn't validate.

My model:

class Question < ApplicationRecord
  acts_as_paranoid
  validates_as_paranoid

  validates_uniqueness_of_without_deleted :identifier, allow_blank: true
end

The spec:

describe Question, type: :model do
  let(:question) { create(:question) }

  it_behaves_like 'a Paranoid model'

  it 'validates_uniqueness_of_without_deleted' do
    question.update! identifier: :reason
    new_question = Question.new(text: 'Will zzak help?', identifier: :reason)

    expect(new_question.valid?).to be_falsy

    question.destroy

    expect(new_question.valid?).to be_truthy
  end
end

The spec fails..

Rails 5, Ruby 2.3.0
Let me know if you need more details about my app/configuration.

disable panaroid with some models

I'm using Rails 5, i want the majority of models acts_as_panaroid so i did this

class ApplicationRecord < ActiveRecord::Base
  acts_as_paranoid
  self.abstract_class = true
end

Now all my models are acting as panaroid, but i want to exclude some of them

Exemple:

class ClassA < ApplicationRecord
end
class ClassB < ApplicationRecord
end
class ClassC < ApplicationRecord
end
class ClassD < ApplicationRecord
end

I want ClassC not to acts_as_panaroid

is there any solution for that??

wrong sql generated when used with database_cleaner and multiple database adapters

We found and issue, when acts_as_paranoid is used with database_cleaner gem and multiple database adapters like mysql and postgresql. We had the following errors

Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '."deleted_at" IS NULL) LIMIT 1' at line 1: SELECT users.* FROM users WHERE users.id = 42 AND ("users"."deleted_at" IS NULL) LIMIT 1

Pushed #49 for fixing it

deleted_after_time not working properly

Hi guys, I just installed the latest acts_as_paranoid and was trying to test out deleted_after_time.

irb(main):002:0> Item.deleted_after_time(2.years.ago)
  Item Load (0.7ms)  SELECT "items".* FROM "items" WHERE ("items"."deleted_at" IS NULL) AND (deleted_at > '2014-01-05 22:05:30.919562')
=> #<ActiveRecord::Relation []>

There are definitely items that match, but it seems like the 1st WHERE condition is causing the problem. I don't think we need it. Am I missing something?

with_deleted when both relations deleted does not work

@offices = Office.with_deleted.includes({client_with_deleted: [:offices]}, :slots)
                   .order('clients.name, offices.name')

@offices.each do |office|
  office_count = office.client_with_deleted.offices.count
end

raise undefined method `offices' for nil:NilClass when office and client are deleted.

Unknown column 'users.deleted_at' error when running migration

Hello, I'm having an issue with migrations on models with acts_as_paranoid. Here's what the migration looks like :

class RemovePhoneNumberFromUser < ActiveRecord::Migration
  def up
    remove_column :users, :phone_number
    remove_column :users, :phone_number_extension
  end
end

When I run a rake db:migrate from a clean database, I get the following error :

StandardError: An error has occurred, all later migrations canceled:

Mysql2::Error: Unknown column 'users.deleted_at' in 'where clause': SELECT `users`.* FROM `users`  WHERE `users`.`deleted_at` IS NULL

My User model has the line acts_as_paranoid in it. Any idea where the issue might come from?

Works with associations?

First, I can't seem to find much documentation at all on this gem.

Second, is there any way to use this with associations? For example, user.groups_with_deleted or something along those lines?

ArgumentError: Unknown key: :with_deleted

Hi there, i found an issue with rails 5

ArgumentError: Unknown key: :with_deleted. Valid keys are: :class_name, :anonymous_class, :foreign_key, :validate, :autosave, :foreign_type, :dependent, :primary_key, :inverse_of, :required, :polymorphic, :touch, :counter_cache, :optional

For this classical model :

class Payment < ApplicationRecord
acts_as_paranoid
belongs_to :payment_method, with_deleted: true
end

Anyone has the same problem ?

Thanks !

`#reload` doesn't raise `ActiveRecord::RecordNotFound` for soft deleted objects

Hey there!

Not sure if this is a bug or the intended behaviour, but we had a test that looked a little like this:

it 'deletes the book' do
  delete :destroy, id: book.id
  expect { book.reload }.to raise_error ActiveRecord::RecordNotFound
end

Which worked without acts_as_paranoid but fails with it because #reload doesn't raise ActiveRecord::RecordNotFound for soft deleted objects.

We can work around this by changing our assertion to this:

expect { Book.find(book.id) }.to raise_error ActiveRecord::RecordNotFound

But I thought it may be worth discussion / what do you think?

Thanks! ๐Ÿ’–

Using with_deleted on belongs_to breaks class reflections?

I am upgrading a Rails 3.2 app to 4.0 that uses acts_as_paranoid, and I've switched to this gem. After upgrading, many of tests were failing with

NoMethodError (undefined method `parent_reflection' for true:TrueClass):

which was coming from the ActiveRecord reflections method. Each association in AR adds an entry to the _reflections hash. When I do something like:

class Child < ActiveRecord::Base
  acts_as_paranoid
  belongs_to :parent, with_deleted: true
end

it adds a (seemingly) bogus entry into _reflections

Child._reflections.keys => ["parent", :with_deleted]
Child.reflections => NoMethodError (undefined method `parent_reflection' for true:TrueClass)

(the with_deleted value is true in the hash)

I have confirmed this is a brand new, vanilla Rails project. If I comment out https://github.com/ActsAsParanoid/acts_as_paranoid/blob/master/lib%2Facts_as_paranoid%2Fassociations.rb#L16 then the error goes away. It seems that added with_deleted to the result is bad...should it be removed? Or am I using this incorrectly?

I'll gladly issue a PR to remove that line, but I am not convinced enough that I am not just being stupid.

Scope chaining broken on Rails 4.2.5.1?

Hey there,

Just having some issues with scope chaining on Rails 4.2.5.1.

This works in Rails 3.7

SomeModel.unscoped.with_deleted

However, in our Rails app on 4.2.5.1 it doesn't; we get a NoMethodError for undefined method with_default_scope.

The issue seems to be with lib/core/acts_as_paranoid/core.rb, line 82. That is calling the query method that was present in Rails 3 but not 4 AFAICT.

The temporary workaround seems to be to not use unscoped in scopes for chaining upstream from e.g. with_deleted.

Could we please get a fix for this?

'Recovering dependent associations' doesn't work

Hi!

I've got a problem with recovering dependent associations. Here is my case.

I have a SuperUser class inherited from User class and this SuperUser has_one profile (SuperUsersProfile):

SuperUser:

class SuperUser < User
  acts_as_paranoid
  has_one :profile, class_name: 'SuperUsersProfile', inverse_of: :super_user, dependent: :destroy
  ...
end

SuperUsersProfile:

class SuperUsersProfile < ActiveRecord::Base
  acts_as_paranoid
  belongs_to :super_user, inverse_of: :profile
  ...
end

When I destroy particular SuperUser, it works perfectly fine. SuperUser is destroyed with its profile. Unfortunately it doesn't work for recovering. When I try to recover SuperUser it recovers only SuperUser and SuperUsersProfile is not recovered. I would appreciate if you could check it.

It's not a big deal for me. I wrote a separate module to handle that so it works. But maybe someone would come across this case also in the future.

Inheritance behaviour

Hi there,

I know it is almost christmas, but this situation doesn't leave my mind and I have to write it down.
Congrats for this great plugin!

I'm using CITIER, so I have a main class named Media and many children, like FileMedia, PackageMedia and so on. Also, I have a table for every single table and, for retrieving children data, I use views, like view_file_media, view_package_media, ...).

So I started using acts_as_paranoid! To make long story short, the problem is default_scope defined in Media, specifically default_scope { where(paranoid_default_scope_sql) }.

When I try to retrieve only PackageMedia data (using PackageMedia.all), I got this SQL error:

ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'media.deleted_at' in 'where clause'

... because of this query:

SELECT 'view_package_media'.* FROM 'view_package_media' WHERE 'media'.'deleted_at' IS NULL AND 'view_package_media'.'type' IN ('PackageMedia')

... of course.

After a little debugging, i've found out it's all about Arel::Table (self.scoped.table[paranoid_column].eq(nil).to_sql), since in the moment the default_scope gets executed, it uses the Media table and not the PackageMedia view.

I could solve it by replacing

default_scope { where(paranoid_default_scope_sql) }

... with

default_scope :conditions => { :deleted_at => nil } (still not solved for situations where it uses string type).

What happens here is that the :conditions hash gets processed using PackageMedia context and not Media's, then it works!

Well, what do you think about it? Is it a possible solution or can you tell me another road to try?
Anyway, I would be happy to fork it and create a pull request.

Regards,
Vieira

feature request: hook for delete and recover

I was wondering if it could be possible to have a hook for remove and recover calls, something like "on_delete" or "on_recover". It could be useful for records with an external entity like "files" it would allow the developer to move deleted files to a "recycle bin" directory and remove them later or recover them if she needs.

Fix tests for Rails 5

See #62: build

1) Failure:

ValidatesUniquenessTest#test_should_validate_without_deleted [/home/travis/build/ActsAsParanoid/acts_as_paranoid/test/test_validations.rb:16]:

Expected true to not be truthy.

DEPRECATION WARNING

DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from singleton class at /Users/user/.rvm/gems/ruby-2.3.1@rails5/bundler/gems/acts_as_paranoid-c2db19554dda/lib/acts_as_paranoid/associations.rb:6)
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from block in included at /Users/user/.rvm/gems/ruby-2.3.1@rails5/bundler/gems/acts_as_paranoid-c2db19554dda/lib/acts_as_paranoid/preloader_association.rb:11)

undefined method `validate_find_options' for class `

With the latest version (5.0.rc1) I seem ot be getting an error generating a rails migration for acts_as_paranoid for a model that already exists.

rails generate migration MakeEventParanoid
/home/dominusk/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:89:in rescue in block (2 levels) in require': There was an error while trying to load the gem 'acts_as_paranoid'. Gem Load Error is: undefined methodvalidate_find_options' for class `#Class:ActiveRecord::Base'

Note I am running Rails 5.0 along with Devise, Pundit and Rolify. It eventually traces back to my application.rb config line 17 which is

Bundler.require. Below is a snapshot of the application.rb code from line 1-17

`require_relative 'boot'

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
# require "sprockets/railtie"
require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)`

I have confirmed the migration creation will work fine if I comment out the paranoid gem. So definitely something related to acts_as_paranoid

Create :without_deleted scope for things like acts_as_list

So acts_as_list has functions that are unscoped, which is unfun when using acts_as_paranpod. This is an easy fix though:

  1. Turn default_scope { where(paranoid_default_scope_sql) } into default_scope { without_deleted }
  2. Create a new scope: scope :without_deleted, -> { where(paranoid_default_scope_sql) }
  3. Document it

Thoughts?

delete_all with associations

i have upgraded from rails 4.0.2 to 4.1.8, and i'm facing this issue with associations

class Reservation < AR::Base
  has_many :bookings
end

class Booking < AR::Base
  acts_as_paranoid

  belongs_to :reservation
end

r = Reservation.create(params)
b = Booking.create(reservation: r)

# does not work. does not set deleted_at to some Time.
# sql that im seeing is:
#  UPDATE "bookings" SET "reservation_id" = NULL WHERE
#    ("bookings"."deleted_at" IS NULL) AND 
#    "bookings"."reservation_id" = $1  [["reservation_id", 1]]
r.bookings.delete_all

# works, sets deleted_at to proper value.
# sql that im seeing is:
# UPDATE "bookings" SET "deleted_at" = '2015-01-02 13:07:06.374754' WHERE
#    ("bookings"."deleted_at" IS NULL) AND "bookings"."id" IN (1)
Booking.where(id: r.bookings.map(&:id)).delete_all

is this a known issue?

has_many autosave doesn't work on paranoid value

Hello,

When modifying a child object on a has_many association, the autosave option allows the child to save when the parent saves. This doesn't seem to work when manually setting the paranoid value because the records are skipped if they're destroyed (https://github.com/rails/rails/blob/master/activerecord/lib/active_record/autosave_association.rb#L397). The problem stems from aliasing destroyed? to deleted? which uses the changed value when checking if it's destroyed?

Test case exposing the problem : 6697e39

Any thoughts on solutions?

Let me know if I can help.
Thanks!

destroy! and destroy_fully! not documented

The documentation is incorrect for Real Deletion.

destroy! no longer does the actual deletion. It needs to be called twice, just like destroy. If you want something destroyed permanently you need to call destroy_fully!

Per the commit comment:

Soft destroy dependents
The dependent destroy callback mechanism in Rails calls destroy! instead
of destroy for has_many associations. With the existing implementation
of acts_as_paranoid, this would unintentionally cause dependent objects
to be hard-destroyed. This change makes destroy and destroy! identical,
and adds a separate destroy_fully! method for full destroy.

Why the project is failing?

The project is failing and I have updated my gems, we are depending on this gem at the production level, can I ask what is the problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.