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

Select which models to become permanent records #92

Open
mariochavez opened this issue Jun 27, 2017 · 4 comments
Open

Select which models to become permanent records #92

mariochavez opened this issue Jun 27, 2017 · 4 comments

Comments

@mariochavez
Copy link

Hi,

I have a case where not all model in my app needs to become permanent_records but the issue is that Permanent Records adds itself to all Activerecords with:

ActiveSupport.on_load(:active_record) do
  ActiveRecord::Base.send :include, PermanentRecords::ActiveRecord
end

My proposal is to have a setting to:

  1. Decide if we want Permanent Records in all models - as it is right now -
  2. Add Permanent Records to only those that need it.

Please let me know if you are willing to accept a PR for this.

@JackDanger
Copy link
Owner

As long as it doesn't break the default functionality for existing users then a PR for this would be lovely!

@mariochavez
Copy link
Author

@JackDanger sure by default it will work as it is.

@joel
Copy link
Collaborator

joel commented Jul 3, 2017

@mariochavez very good initiative 👍

@pjungwir
Copy link

pjungwir commented Mar 1, 2018

I hope someone adds this, but in the meantime here is a workaround:

class MyModel < ApplicationRecord
  def self.dangerous_class_method?(method_name)
    # Let us define our own not_deleted scope,
    # overriding the one defined by permanent_records.
    # For more info see:
    # https://github.com/JackDanger/permanent_records/issues/92
    if method_name.to_s == 'not_deleted'
      false
    else
      super(method_name)
    end
  end
end

This approach to replacing class methods defined on ActiveRecord::Base seems to be endorsed by the Rails team.

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

No branches or pull requests

4 participants