diff --git a/activestorage/app/models/active_storage/attachment.rb b/activestorage/app/models/active_storage/attachment.rb index 9b626be82d..3c47fa2d29 100644 --- a/activestorage/app/models/active_storage/attachment.rb +++ b/activestorage/app/models/active_storage/attachment.rb @@ -7,7 +7,7 @@ require "active_support/core_ext/module/delegation" # on the attachments table prevents blobs from being purged if they’re still attached to any records. # # Attachments also have access to all methods from {ActiveStorage::Blob}[rdoc-ref:ActiveStorage::Blob]. -class ActiveStorage::Attachment < ActiveRecord::Base +class ActiveStorage::Attachment < ActiveStorage::Record self.table_name = "active_storage_attachments" belongs_to :record, polymorphic: true, touch: true diff --git a/activestorage/app/models/active_storage/blob.rb b/activestorage/app/models/active_storage/blob.rb index 8ba9d7a9da..18c8c9973a 100644 --- a/activestorage/app/models/active_storage/blob.rb +++ b/activestorage/app/models/active_storage/blob.rb @@ -14,7 +14,7 @@ # Blobs are intended to be immutable in as-so-far as their reference to a specific file goes. You're allowed to # update a blob's metadata on a subsequent pass, but you should not update the key or change the uploaded file. # If you need to create a derivative or otherwise change the blob, simply create a new blob and purge the old one. -class ActiveStorage::Blob < ActiveRecord::Base +class ActiveStorage::Blob < ActiveStorage::Record # We use constant paths in the following include calls to avoid a gotcha of # classic mode: If the parent application defines a top-level Analyzable, for # example, and ActiveStorage::Blob::Analyzable is not yet loaded, a bare diff --git a/activestorage/app/models/active_storage/record.rb b/activestorage/app/models/active_storage/record.rb new file mode 100644 index 0000000000..2c50ae59de --- /dev/null +++ b/activestorage/app/models/active_storage/record.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class ActiveStorage::Record < ActiveRecord::Base #:nodoc: + self.abstract_class = true +end + +ActiveSupport.run_load_hooks :active_storage_record, ActiveStorage::Record diff --git a/activestorage/app/models/active_storage/variant_record.rb b/activestorage/app/models/active_storage/variant_record.rb index 438b31af87..4e552c63ec 100644 --- a/activestorage/app/models/active_storage/variant_record.rb +++ b/activestorage/app/models/active_storage/variant_record.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class ActiveStorage::VariantRecord < ActiveRecord::Base +class ActiveStorage::VariantRecord < ActiveStorage::Record self.table_name = "active_storage_variant_records" belongs_to :blob diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb index 1988d82b13..e574dcea37 100644 --- a/railties/test/application/loading_test.rb +++ b/railties/test/application/loading_test.rb @@ -133,7 +133,11 @@ class LoadingTest < ActiveSupport::TestCase require "#{rails_root}/config/environment" setup_ar! - initial = [ActiveStorage::Blob, ActiveStorage::Attachment, ActiveRecord::SchemaMigration, ActiveRecord::InternalMetadata, ApplicationRecord].collect(&:to_s).sort + initial = [ + ActiveStorage::Record, ActiveStorage::Blob, ActiveStorage::Attachment, + ActiveRecord::SchemaMigration, ActiveRecord::InternalMetadata, ApplicationRecord + ].collect(&:to_s).sort + assert_equal initial, ActiveRecord::Base.descendants.collect(&:to_s).sort.uniq get "/load" assert_equal [Post].collect(&:to_s).sort, ActiveRecord::Base.descendants.collect(&:to_s).sort - initial