Take AR affixes into account for AStorage models
All of ActiveStorage database modeltable nameshave been hard coded. Therefore, ActiveRecord::Base.(prefix|suffix) were not taken into consideration. To fix this we remove the hard coded lines. But then we need to also override an internal method for specifying the prefix because of a mystical ActiveRecord/ActiveStorage sync issue (Suffix does not appear to have the issue) Some tests were refactored to remove hard coded table name references, making ActiveStorage test suite compatible with ActiveRecord config.
This commit is contained in:
parent
c057edaaad
commit
4ca61ffacb
@ -1,3 +1,8 @@
|
||||
* Fix all Active Storage database related models to respect
|
||||
`ActiveRecord::Base.table_name_prefix` configuration.
|
||||
|
||||
*Chedli Bourguiba*
|
||||
|
||||
* Fix `ActiveStorage::Representations::ProxyController` not returning the proper
|
||||
preview image variant for previewable files.
|
||||
|
||||
|
@ -18,8 +18,6 @@
|
||||
# # preloads blobs and variant records (if using `ActiveStorage.track_variants`)
|
||||
# User.first.avatars.with_all_variant_records
|
||||
class ActiveStorage::Attachment < ActiveStorage::Record
|
||||
self.table_name = "active_storage_attachments"
|
||||
|
||||
##
|
||||
# :method:
|
||||
#
|
||||
|
@ -17,8 +17,6 @@
|
||||
# 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 < ActiveStorage::Record
|
||||
self.table_name = "active_storage_blobs"
|
||||
|
||||
MINIMUM_TOKEN_LENGTH = 28
|
||||
|
||||
has_secure_token :key, length: MINIMUM_TOKEN_LENGTH
|
||||
|
@ -1,8 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActiveStorage::VariantRecord < ActiveStorage::Record
|
||||
self.table_name = "active_storage_variant_records"
|
||||
|
||||
belongs_to :blob
|
||||
has_one_attached :image
|
||||
end
|
||||
|
@ -53,7 +53,7 @@ def rerun_migration
|
||||
end
|
||||
|
||||
def active_storage_tables
|
||||
[:active_storage_blobs, :active_storage_attachments, :active_storage_variant_records]
|
||||
@active_storage_tables ||= ActiveStorage::Record.descendants.map { |klass| klass.table_name.to_sym }
|
||||
end
|
||||
|
||||
def primary_key(table)
|
||||
|
Loading…
Reference in New Issue
Block a user